So how do you get a sub-string in Python? Well, Python has a handy dandy feature called “slicing” that can be used for getting sub-strings from strings. But first, we have to go over a couple of things to understand how this works. Slicing Python Objects Strings, in Python, are arrays of characters, except they [...]
Articles Tagged: string
Cutting and slicing strings in Python
Python strings as sequences of characters Python strings are sequences of individual characters, and share their basic methods of access with those other Python sequences – lists and tuples. The simplest way of extracting single characters from strings (and individual members from any sequence) is to unpack them into corresponding variables.
|
1 2 3 4 5 6 7 8 9 10 |
>>> s = 'Don' >>> s 'Don' >>> a, b, c = s # Unpack into variables >>> a 'D' >>> b 'o' >>> c 'n' |
Unfortunately, it’s not [...]