Dictionary: Key-value pairs exist. Key value
stu={
' Name ': ' Zhangsan ',
' Gender ': ' femanl ',
' Age ': 17
}
Print (STU)
#增加字典值
stu["Score"]=87
Stu.setdefault (' dictinct ', ' Nanshan ') #已经存在就不添加 sstu.update (xx) #把一个字典加入到另外一个字典里面
#删字典值
Stu.pop (' age ')
Del stu[' score ']
Stu.clear () #清空字典
#查字典值
Print (STU)
Print (Stu.get (' Age ', ' 12 '))
Ganso
Cities = (' Beijing ', ' Shanghai ') #一旦定义好, no more changes.
Print (Cities[0])
#修改元祖至不能通过常规的方式 to create a new
#删除元祖, could not have been subscript the way to Del Delete the whole
Del aities
Common string methods: (Built-in functions)
# Print (Name.count (' t ')) #查询次数
# Print (Name.endswith ('. jpg ')) #判断字符串是否以xx结尾
# Print (Name.startswith (' 138 ') #判断字符串是否以xx开头
# Print (Name.upper ()) #都给你变成大写的
# Print (Name.lower ()) #都变成小写的
# Print (Name.find (' P ')) # When it cannot find the element, it will return 1
# print (Name.isdigit ()) #判断是否为纯数字
# Print (Name.isspace ()) #判断是否全都是空格
# Print ( Name.strip ()) #去掉字符串两边的东西, by default is the
# print (Name.lstrip ()) #只去掉左边的
# Print (Name.rstrip ()) of the whitespace and newline characters to be adjusted #只去掉右边的
# Print (Name.replace (' abc ', ' Look ')) #替换字符串, replace the front with the following
# name = ' 5 '
# print (Name.zfill (2)) #在前面补0
names = "Lxy, ZYF,WDZ,NL,WY,GFW '
# Print (Names.split (', ')) #1, split the string, 2, turn the string into a list 3, the default is separated by a space and newline characters
Stus = [' Lxy ', ' zyf ', ' Wdz ', ' nl ', ' WY ', ' GFW ']
' Lxy, zyf, Wdz '
print ('; '). Join (Stus)) #1, yes. List becomes 2 of a string, concatenated with a string
Import string
Print (string.ascii_letters) #所有的大写 + lowercase Letters
Print (string.ascii_lowercase) #所有的小写字母
Print (string.ascii_uppercase) # All uppercase letters
Print (string.digits) #所有的数字
Print (string.punctuation) #所有的特殊字符
# Print (Name.format ())
# Print (Name.format_map ())
# print (name[1]) #字符串也是可以根据下标来取值的
File Read and write:
Open files can be used with the open () function in Python
Ss
Python Basics dictionary, Ganso, Common string method, file read and write