Useful string built-in function (c)

13 is, The rstrip () method

The new string generation after rstrip () Delete the end of the string specified character string (default is a space), delete the end of the string to return the specified character string.

Syntax: str . Rstrip ([ chars ])

chars - the specified character deleted (default is a space)

str7 = "STudy1"
str8 = "www.studuy.com "
print(str7.rstrip("1"))
print(str8.rstrip())

 

 14, split () method

Slicing through the specified delimiter string, it returns a list of strings after division.

语法:str.split(str="", num=string.count(str))

str - separator, default for all null characters, including spaces, linefeed (\ n-), tab (\ t) and the like.

num - the number of divisions. Defaults to -1, i.e., all separated.

If the second parameter value is specified num, num + 1 is sub-divided into a string.

url = "https://www.runoob.com/python3/python3-string-split.html"
url2 = url.split(".")
print(url2)
url3 = url.split("/")
url4 = url.split("/", 1)
url5 = url.split("/", 2)
print(url3)
print(url4)
print(url5)

 

 15、strip()

For removing head and tail of the string specified character (space by default) or a sequence of characters. Returns a string head and tail removed new string specified character sequence.

 Syntax: STR . Strip ([ chars ]);

chars - remove the head and tail string specified sequence of characters.

 

str = 'qweeerererq12232qwe'
print(str.strip('qwe'))

 

 

str = '123132231213321312==321312213231123132'
print(str.strip('123'))

 

 

. 1, Strip ()  when treated without parameters, the default is to remove white space on both sides, for example: / n-,  / R & lt,  / T,  '').

2, delete multiple characters: as long as there is a character corresponding to the beginning and end of which is deleted, regardless of the order, until the first character which is not included in the till.

16, Upper () method

The string is converted to lowercase size, returned lowercase to uppercase letters of the string.

Syntax: str.upper ()

str = 'haohao'
str1 = "HAH"
print(str.upper())
print(str.isupper())
print(str1.isupper())

 

Guess you like

Origin www.cnblogs.com/keepkeep/p/11571129.html