-
String type
Split splits a string by specifying a delimiter
Example:
Name = "Huang Zhong"
Print (Name.split ())
Strip remove character from string header and trailing, default space, Lstrip remove left character, Rstrip remove right character
Example:
Name = "Alex"
Print (Name.strip ())
Capitalize first letter to uppercase
Example:
Name = "Alex"
Print (Name.capitalize ())
Casefold all caps to lowercase, can convert multiple languages
Example:
Name = "AleX"
v = name.casefold ()
Print (v)
Lower all caps to lowercase, only English is converted
Example:
Name = "AleX"
v = name.casefold ()
Print (v)
Center text centered, padding with other characters in white space, padding by default blank character
Example:
Name = "Alex"
v = name.center (20, ' * ')
Print (v)
Number of occurrences of the count substring in the parent string
Example:
Name = "CNDKLSDNRFKNSV"
num = Name.count ("D")
NUM1 = Name.count ("D", 5) #从第5个索引开始计算
num2 = Name.count ("D", 5, 9) #计算从第5到第9之间d出现的次数
Print (num)
StartsWith whether to start with a character, or return true, otherwise false
Example:
Name = "Alex"
v = Name.startswith ("Al")
Print (v)
EndsWith whether to start with a character, or return true, otherwise false
Example:
Name = "Alex"
v = name.startswith ("ex")
Print (v)
Expandtabs Find tab and replace
Example:
Name = "Nsdl\tajnfcks\tsns"
v = name.expandtabs (#替换成20个字符), insufficient padding
Print (v)
Find finds the index position of the subsequence, not found return-1
Example:
Name = "Alex"
v = name.find ("o") #-1
Print (v)
Index finds the indexed position of the sub-sequence, no error found
Example:
Name = "Alex"
v = Name.index ("a")
Print (v)
format string Formatting
Example:
Name = v = Name.format (,,) (v) name = v = Name.format (=,=, =) (v)
Whether the isalnum is a number, a character, a Chinese character
Example:
Name = v = name.isalnum () (v) num = "two" V1 = Num.isdecimal () # ' 123 ' v2 = Num.isdigit () # ' 123 ' V3 = Num.isnumeric () # ' 123 ', ' two '
This article is from the "Linux Technology" blog, so be sure to keep this source http://xiaojishu.blog.51cto.com/4278020/1923283
Python Data type Learning