码迷,mamicode.com
首页 > 编程语言 > 详细

python_day02 学习知识点

时间:2017-07-10 13:18:00      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:weight   code   个数   font   strip()   分割   数据类型   类型   其他   

当天要学习知识点:

1、基本数据类型

2、字符编码

4、文件处理

 

1、基本数据类型

字符串str:

str=hello nice to meet you Name:{name},Age:{age}    
print(str[0])       #取值
# 字符串str的常用操作
print(str[1:9:2])      #切片 步长为2
print(str.strip())  #去掉字符串前后空格
print(str.split())  #分割 可指定分割符为*或|
print(len(str))     #长度
# 字符串str的其他操作
print(str.upper())  #大写
print(str.lower())  #小写
print(str.center(60,*))     #指定字符个数,字符串居中,其他*补全
print(str.count(o))   #统计指定字符的个数,空格也算是一个字符
print(str.find(o))    #列出‘o‘所在位置信息,不存在输出为-1
print(str.index(o))   #列出‘o‘所在位置信息,不存在则报错
print(str.format(name=liwj,age=17))     #格式化字符串,替代{}中的内容
print(str.replace(o,O,2))   #替换指定字符为其他字符,可指定替换次数
print(str.startswith(h))      #判断字符串开头和结尾信息
print(str.endswith(o))
print(str.isdigit())    #判断字符串中字符是否是为数字
结果信息:
h
el i
hello nice to meet you Name:{name},Age:{age}
[‘hello‘, ‘nice‘, ‘to‘, ‘meet‘, ‘you‘, ‘Name:{name},Age:{age}‘]
48
HELLO NICE TO MEET YOU NAME:{NAME},AGE:{AGE}    
hello nice to meet you name:{name},age:{age}    
******hello nice to meet you Name:{name},Age:{age}    ******
3
4
4
hello nice to meet you Name:liwj,Age:17    
hellO nice tO meet you Name:{name},Age:{age}    
True
False
False
列表list:

python_day02 学习知识点

标签:weight   code   个数   font   strip()   分割   数据类型   类型   其他   

原文地址:http://www.cnblogs.com/liweijing/p/7144998.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!