Python Strings
Python Strings
2
SKILLPILLS
Treating strings as lists
>>> s = "Skill Pills are awesome!”
False
True
>>> s[0]
'S'
>>> s[0:11]
'Skill Pills'
3
SKILLPILLS
Treating strings as lists
>>> 3 * "Hip hip? Hooray! "
'Hip hip? Hooray! Hip hip? Hooray! Hip hip? Hooray! '
>>> len(s)
24
>>> s.index("awesome")
16
[2, 1, 2]
4
SKILLPILLS
String methods
>>> s="skill pills"
>>> s.capitalize()
'Skill pills'
>>> s.title()
'Skill Pills’
>>> s.upper()
'SKILL PILLS'
>>> s.islower()
True
>>> s.isupper()
False
5
SKILLPILLS
String methods
'hi'
>>> s.split()
['skill', 'pills']
>>> s.find("pills")
>>> s.replace("pills","syringes")
'skill syringes’
6
SKILLPILLS
Formatting
7
SKILLPILLS
Formatting numbers
8
Exercices SKILLPILLS
• Go to http://rosalind.info/
• Register
• First: Python village
• Second: Bioinformatics Stronghold
9
(Padding and truncating) SKILLPILLS
10
(Other possibilities) SKILLPILLS
★ '2001-02-03 04:05'
11