String processing is definitely the focus of any language.
str. partition (Sep)
Split the string at the first occurrence of Sep, and return a 3-tuple containing the part before the separator, T He separator itself, and the part after the separator. If The separator is not found, return a 3-tuple containing the string itself, followed by both empty strings.
mystr = " hello,!!! World " print (Mystr.partition ( Span style= "COLOR: #800000" > " , " Span style= "color: #000000")) # output ( " hello ' , < span>, ' !!! World ")
str. split (sep=none, maxsplit=-1)
Return A list of the words in the string, using Sep as the delimiter string. If Maxsplit is given, at most maxsplit splits be done (thus, the list would have at most maxsplit+1 elements ). If maxsplit is isn't specified or -1 , then there was no limit on the number of splits (all possible splits are Made).
str. join (iterable)
Return a string which is the concatenation of the strings in iterable. A'll be TypeError raised if there is any non-string values in iterable, including bytes objects. The separator between elements is the string providing this method.
mylist = [ " first " , " second " , " third " ]mystr = " # " .join (mylist) print (MYSTR) # Output:first#second#third
str. startswith (prefix, start, end)
Return True If string starts with the prefix, otherwise return False . prefix can also is a tuple of prefixes to look for. With optional start, the test string beginning at that position. With optional end, stop comparing string at that position.
" This is a string EXAMPLE....WOW!!! " Print (Mystr.startswith ('this')) Print (Mystr.startswith ('is', 2, 4)) Print (Mystr.startswith ('this', 2, 4))
The output is as follows:
True
True
False
Python string processing