@@ -148,11 +148,12 @@ Indexing with negative values works like this:
148
148
149
149
## String methods
150
150
151
- Python's strings have many useful methods. [ The official documentation]
152
- (https://docs.python.org/3/library/stdtypes.html#string-methods ) covers
153
- them all, but I'm going to just show some of the most commonly used ones
154
- briefly. Python also comes with built-in documentation about the string
155
- methods and we can run ` help(str) ` to read it.
151
+ Python's strings have many useful methods.
152
+ [ The official documentation] ( https://docs.python.org/3/library/stdtypes.html#string-methods )
153
+ covers them all, but I'm going to just show some of the most commonly
154
+ used ones briefly. Python also comes with built-in documentation about
155
+ the string methods and we can run ` help(str) ` to read it. You can also
156
+ get help about one string method at a time, like ` help(str.upper) ` .
156
157
157
158
Again, nothing can modify strings in-place. Most string methods
158
159
return a new string, but things like ` our_string = our_string.upper() `
179
180
False
180
181
>> > our_string.replace(' World' , ' there' )
181
182
' Hello there!'
182
- >> > our_string.replace(' l ' , ' ł ' , 1 ) # only replace one l
183
- ' Hełlo World!'
183
+ >> > our_string.replace(' o ' , ' @ ' , 1 ) # only replace one o
184
+ ' Hell@ World!'
184
185
>> > ' hello 123 ' .lstrip() # left strip
185
186
' hello 123 '
186
187
>> > ' hello 123 ' .rstrip() # right strip
0 commit comments