Python开发【第4节】【Python数据类型】

1、Python数据类型

Number(数字)
    int
    bool
    float
    complex(复数)
String(字符串)
List(列表)
Tuple(元组)
Sets(集合)
Dictionary(字典)

2、

3、字符串

字符串操作

str = "hello word"

find():检查str是否包含子str,从左向右查找,若是:返回开始的索引值,否返回-1

str.find("word")
>>>6
str.find("country")
>>>-1


index():功能同find,区别在于,若str不包含子str,返回异常

str.index("word")
>>>6
str.index("country")
>>>Traceback


rfind()与rindex():功能上同,区别是从右向左查找


count():返回str出现次数

str.count("hello")
>>>1


replace():将str1替换成str2,替换count次

str.replace(str1,str2,count)


spilt():按照空格对字符串进行切割,
str.spilt(str" ")


capitalize():首字母大写

str.capitaliz()
>>>Hello world

title():每个单词首字母大写

str.title()
>>>Hello Word


startwith():以**开始
endwith():以**结尾
lower():大写转小写
upper():小写转大写

  

猜你喜欢

转载自www.cnblogs.com/loser1949/p/9496049.html