String
Common methods of operation. Count (). Find (). Join (). Encode (). Decode (). EndsWith (). Startswitch (' A '). IsDigit (). Strip (). Replace (' xx ', ') . Split (', ') #以xx来分割字符串, returns a List.splitlines () #以换行符来分割字符串, returns a list
#name = ' Li,xixi,ll,yy '
# Print (Name.count (' l ')) #统计某个字符串出现的次数
# Print (Name.index (' l ')) #返回某个元素第一次出现的下标
# Print (Name.capitalize ()) #首字母大写, the string original value does not change
# Print (Name.casefold ()) #首字母小写
# Print (Name.center, '-') #将字符串放在指定长度的符号中间, 50 is the specified length, '-' is the symbol to be filled, the specified length must exceed the string length to have effect
# #效果为------------------Li,xixi,ll,yy-------------------
# print (' Welcome login '. Center (50, ' * '))
# #*********************** Welcome to login ***********************
# Print (Name.encode ()) #解码, the default parameter is Utf-8
# #b ' Li,xixi,ll,yy ' B stands for binary type
# Bye_name=name.encode ()
# print (bye_name) #byte类型
# #b ' Li,xixi,ll,yy '
# Bye_name.decode () #编码, Bytes only decode method
# Print (Bye_name.decode ()) #将byte类型转为正常的字符串
# #li, Xixi,ll,yy
#
# Print (Name.endswith ('. com ')) #判断字符串是否以xx结尾, returns a Boolean value
# Print (Name.find (' ll ')) #查找字符串, return subscript
# #find与index的区别是, index to find a nonexistent character will error, and find is return-1
# Print (Name.find (' hh ', 8,19)) #指定从8个字符开始查找, to end of 19
# Print (Name.find (' hh ', 8)) #从第8个开始查找字符串hh
#
# Print (Name.expandtabs ()) #如果字符串中有 \ t, repeat \ t 30 times.
#\t represents the TAB key, 4 spaces, \ n for line break
# str= ' Zhang\txixi '
# Print (Str.expandtabs (50))
#zhang Xixi
# print (' Welcome {name} login '. Format (name= ' ni ')) #格式化输出
# print (' Welcome {name} login '. Format_map ({"name": "Haha"}) #格式化输出, the value is a dictionary
#
# print (' DSF good '. Isalnum ()) #是否包含数字或字母或者中文
# print (' AbA '. Isalpha ()) #是否是英文字母, returns a Boolean value
# Print (Name.isdigit ()) #判断是否是一个整数
# print (' HHH '. Isidentifier ()) #判断是否是一个合法的变量名
#
# Print (Name.islower ()) #判断字符串是否全都是小写字母
# print (' BB '. Isupper ()) #判断字符串是否全都是大写字母
# print (". Isspace ()) #判断字符串是不是空格
#join方法重要
#addr = ' Beijing '
# print (', '. Join (addr)) #将字符串以, Interval
# #北, Beijing
# names=[' BJF ', ' LW ', ' JJX '
# new_name=str (names) #强制类型转换, str converted to string
# print (': '. Join (names)) #以前面的字符串连接后面的可迭代的对象 (string, list, etc.) inside each element
# #bjf: LW:JJX
Addr= ' Besttest '
# Print (Addr.lower ()) #把所有大写字母变成小写
# Print (Addr.upper ()) #把所有小写字母变成大写
# Print (Addr.lstrip (' B ')) #去除开头的某个字符, default no write parameter is go space
# Print (Addr.rstrip ()) #去掉字符串末尾的xx. Default does not write words, go to space
# Print (Addr.strip ()) #去掉字符串两头的xx, default does not write, go to space
#print (addr.replace (' Test ', ' my_test ')) #字符串替换
# Addr.startswith (' a ') #字符串是否以xx开头
# addr.swapcase () #字符串大小写互相转换
Addr= ' Niuhanyang,bjf,liw,lhl,jjx,ccs '
Print (Addr.split (', ')) #按照xx分割字符串, returns a list that does not change the original value
Print (Addr.splitlines ()) #按照换行符进行分割, the return is also a list of
Force type conversion int () str () list () Dict () to cast the type to dictionary type () #查看数据类型
Python Learning Notes---strings