1.2 KiB
title |
---|
String Methods |
TODO: string
basic info
Creation:
An empty string
is created using a pair of quotation marks or apostrophes:
>>> new_string = ''
>>> type(new_string)
<class 'string'>
>>> len(new_string)
0
-
string.find('you')
Returns the lowest position that the substring is found at. -
str.join(iterable)
Join all elements in aniterable
with a specified string. -
str.replace(old, new, max)
method is used to replace the substringold
with the stringnew
for a total ofmax
times. This method returns a new copy of the string with the replacement, and the originalstr
is unchanged. -
string.split(separator, maxsplit)
Returns a list of substrings delimited by theseparator
, an optionalmaxsplit
number of times, and if not specified, the string will be split on all instances of theseparator
. -
string.strip(to_strip)
Returns a string withto_strip
removed from both the beginning and the end of the string. Ifto_strip
is not specified, this will strip all whitespace characters.