1>>> name ="I Love my job!"2>>> name.capitalize ()#Capitalize first letter3 'I Love my job!'4>>> Name.count ("o")#count the number of letters526>>> Name.center (50,"-")#output 50 characters, not enough to "-" completion, and name in the middle; Name.ljust (50, "-") is populated from the last character to satisfy 50 characters; Name.rjust is just the opposite of Ljust. 7 '------------------I Love my job!------------------'
Common practices for strings in Python:
1>>> name ="I am {name},my age}"2>>> Name.find ("am")#Find character position324>>> Name[name.find ("am"):]#strings can also be sliced5 'am {name},my age}'6>>> Name[name.find ("my"):-1]7 'My age was {age'8>>> Name[name.find ("my"):]9 'My age was {age}'Ten One>>> A>>> Name.format (name='Datou', age=' -')#formatted output - 'I am Datou,my Age is'
String judgment:
Name.isalnum #判断name是否是26个字符 + number combination, yes the return value is true, and the return value is False if there are special characters
Name.isalpha #判断是否是存英文字符, including case
Name.isdecimal #判断是否是十进制
Name.isdigit #判断是否是整数
Name.isidentifier #判断是不是一个合法的标识符, equivalent to determining whether a valid variable name
Name.islower #判断是否小写
Name.isnumeric #判断是否是一个数字
Name.isspace #判断是否是空格
Name.istitle #判断首字母是否大写
Name.isprintable #判断是否可打印, the string is not considered, only if it is a TTY file, driver files, etc.
Name.isupper #判断是否全是大学
1>>>Print('+'. Join (["1","2","3"]))#Join Stitching21+2+33>>>Print("'. Join (["1","2","3"]))41235>>>Print('\nhello,world!'. Lstrip ())#remove left or blank lines6 hello,world!7>>>Print('\nhello,world!')8 9 hello,world!Ten>>>Print('hello,world!\n'. Rstrip ())#Remove the right space or blank line One hello,world! A>>>Print('hello,world!\n') - hello,world! - the>>>#Remove the space on either side or empty line with strip
Common operational learning for Python strings