python学习day4--python基础--元组,字符串
1.元组
#只读列表,元组,当希望生成后不被修改则用元组
r=(1,2,3,4,5)
元组
2.字符串,python字符串操作非常丰富,编程时可先查询python本身是否已设计了相关函数
#移除空白
username='alex '
if username.strip()=='alex':
print('welcome')
#如需移除其它字符,比如:\n,就用strip('\n')的方式 #分割
names='alex,jack,rain'
print("names====",names)
name2=names.split(',')
print("name2====",name2)
#将列表用|连起来
name3="|".join(name2)
print("name3=",name3) #格式化
msg="hello,{name},it's been a long {age} since last time spoke"
print("msg===",msg)
msg2=msg.format(name='Minghu',age=333)
print("msg2===",msg2) msg3="haha {0},dddd {1}"
print("msg3==",msg3)
print("format msg3==",msg3.format('Alex',33)) #切片
name='alex Li'
print(name[2:4])
print(name.center(40,'-')) #其它操作
name='alex li'
print("name==",name)
print ("if space in name",(' ' in name))#有没有空格
print(name.capitalize())#首字母大写
print(name.find('l'))#如脜在返回下标,不存在返回-1 age=input("your age:")
if age.isdigit():
age=int(age)
else:
print("invalid data type") print(name.isalnum())
print(name.startswith('al'))
print(name.endswith('li'))
print(name.upper())
一些基本操作
python学习day4--python基础--元组,字符串的更多相关文章
- Python学习笔记-Day2-Python基础之字符串操作
字符串的常用操作包括但不限于以下操作: 字符串的替换.删除.截取.复制.连接.比较.查找.分割等 这里将对字符串的内置操作方法进行总结归纳,重点是以示例的方式进行展示. 使用type获取创建对象的类 ...
- python学习日记(基础数据类型及其方法01)
数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...
- Python学习day11-函数基础(1)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习课程零基础学Python
python学习课程,零基础Python初学者应该怎么去学习Python语言编程?python学习路线这里了解一下吧.想python学习课程?学习路线网免费下载海量python教程,上班族也能在家自学 ...
- Python学习2-列表和元组
Python学习2-列表和元组 标签(空格分隔): 列表 元组 在Python中,最基本的数据结构是序列(sequence).序列中的每个元素被分配一个序号--即元素的位置,也称为索引.索引从0开始. ...
- Python学习系列(三)(字符串)
Python学习系列(三)(字符串) Python学习系列(一)(基础入门) Python学习系列(二)(基础知识) 一个月没有更新博客了,最近工作上有点小忙,实在是没有坚持住,丢久又有感觉写的必要了 ...
- Python学习day12-函数基础(2)
<!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...
- Python学习day05 - Python基础(3) 格式化输出和基本运算符
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习笔记之基础篇(-)python介绍与安装
Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...
- Python学习day16-模块基础
<!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...
随机推荐
- ASCII,GB2312,GBK,Unicode,Utf-8
1.ASCII:American Stardand Code for Information Interchange,是当时美国制定出来的一套编码系统,使用7位或8位二进制来表示西文字符,0-31以及 ...
- java 分页
ListAction.java package com.sy.action; import java.util.List; import com.opensymphony.xwork2.ActionS ...
- OAuth 2.0
国外 OAuth2.0 大全:http://oauth.net/2/ 国内经典:http://www.fising.cn/2011/03/%E4%B8%80%E6%AD%A5%E4%B8%80%E6% ...
- SqlServer刷新所有视图
CREATE PROCEDURE RefreshAllView AS DECLARE MyCursor CURSOR FOR select Name from dbo.sysobjects where ...
- QM04-生产中的QM
集成的计划 生产过程中的生产工序和检验工序逐渐变得更为相互依赖或者说被组合在一起.从而使来自生产和质量检验领域的工作小组共同创建工艺流程. 检验工序 可以把QM检验特性集成到生产计划(PP)模块的工作 ...
- Python2.7.3移除字符串中重复字符(一)
移除重复字符很简单,这里是最笨,也是最简单的一种.问题关键是理解排序的意义: # coding=utf-8 #learning at jeapedu in 2013/10/26 #移除给定字符串中重复 ...
- jsonp跨域原理解析
前言: 跨域请求是前台开发中经常遇到的场景,但是由于浏览器同源策略,导致A域下普通的http请求没法加载B域下的数据,跨域问题由此产生.但是通过script标签的方式却可以加载非同域下的js,因此可以 ...
- 网络IPC:套接字之套接字描述符
套接字是通信端点的抽象.与应用程序要使用文件描述符访问文件一样,访问套接字也需要套接字描述符.套接字描述符在UNIX系统是用文件描述符实现的.事实上,许多处理文件描述符的函数(如read和write) ...
- Computer skills one can learn within one day
Computer related technical skills are usually thought as complicated and difficult to understand. It ...
- X - Urban Elevations
Urban Elevations An elevation of a collection of buildings is an orthogonal projection of the buil ...