string.ascii_letters:所有ASCII字母字符(大小写)。 string.ascii_lowercase:所有小写ASCII字母字符。 string.ascii_uppercase:所有大写ASCII字母字符。 string.digits:所有数字字符(0-9)。 string.hexdigits:所有十六进制数字字符(0-9和a-f)。 string.octdigits:所有八进制数字字符(0-7)。 string.punctuation:所有标...
Capitalizes first letter of each word in a string using loop, split() method # python program to capitalizes the# first letter of each word in a string# functiondefcapitalize(text):return' '.join(word[0].upper()+word[1:]forwordintext.split())# main codestr1="Hello world!"str2="h...
54 55 """ 56 return (sep or ' ').join(x.capitalize() for x in s.split(sep)) 57 58 59 # Construct a translation string 60 _idmapL = None 61 def maketrans(fromstr, tostr): 62 """maketrans(frm, to) -> string 63 64 Return a translation table (a string of 256 bytes long) ...
capitalize():将字符串的第一个字母变成大写,其他字母变小写。对于8位字节编码需要根据本地环境。swapcase():用于对字符串的大小写字母进行转换,大写转小写,小写转大写。title():返回"标题化"的字符串,就是说所有单词都是以大写开始,其余字母均为小写。 这些都是大小写切换,title()并不能除去字符串两端的空白符...
str.capitalize() 将字符串的第一个字母变成大写,其他字母变小写 Return a copy of the string with only its first character capitalized. For 8-bit strings, this method is locale-dependent. str.center(width[, fillchar]) Return centered in a string of length width. Padding is done using the spe...
string_test = "Hello My Friend" srring_test_sub = string_test[:6] 1. 2. 2.2 字符串运算符 下表实例变量a值为字符串 “Hello”,b变量值为 “Python”: 2.3 字符串的内置函数: len(string) # 返回字符串长度 max(str)#返回字符串 str 中最大的字母 ...
'PYTHON STRING' >>> str.lower() #转小写 'python string' >>> str.capitalize() #字符串首为大写,其余小写 'Python string' >>> str.swapcase() #大小写对换 'pYTHON STring' >>> str.title() #以分隔符为标记,首字符为大写,其余为小写 'Python String' 3.>字符串条件判断 1 2 3 4 5...
capitalize(): title(): upper(): lower(): swapcase(): replace(): type(thing) #获取thing的数据类型 变量名只能包含:小写字母、大写字母、数字、下划线,不能以数字开头。 python保留的关键字: ['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'bre...
When it comes to manipulating strings, a common task that we might want to do is capitalize a string (i.e. convert the first character from lowercase to uppercase). Unfortunately, strings are pretty complex because they can support a huge variety of symbols from letters and numbers to ...
If the remaining characters in the string contain capital letters, they are all changed to small letters.Open Compiler str = "hii! Welcome to TUTORIALSPOINT." output=str.capitalize() print("The string after applying the capitalize() function is:", output) ...