



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1 /
will create a substring from my_str index start through to end - 1
my_str='[name:<16}{goals:>8}{points:^6}'
{score:0>4} produces 0018
be included in the output of floating types '{:.1f}'.format(1.725) produces 1.
by the string new; old and new arguments may be string variables or string literals phrase.replace('one', 'two') will replace any occurrence of the word one with two
replaced by the new except only replaces the first count occurrences of old phrase.replace('one', 'two', 5) will replace any occurrances of 'one' with 'two' but will begin looking at index 5
my_str.find('!') will return the index of the '!' in the string
2 /
the string but will begin looking at index start my_str.find('!', 3) will produce the index of the first! on or after index 3
in the string but will begin looking at the index start and will stop at index end - my_str.find('!', 3, 8) will produce the index of the first! but will start looking at index 3 and stop looking at index 8 - 1
occurrence in the string my_str.rfind('!') will give the index of the last! in the string
number of times 'oo' occurs in the string
the numbers 0-
lowercased
4 /
5 /
List Comprehension
Conditional List Comprehension
ensure that a will come before B
dict(Bobby='805-555-2232', Johnny='951-555-0055') dict([('Bobby', '805-555-2232'), ('Johnny', '951-555-0055')])
my_dict['Jose'] = 'B+'
my_dict: ......