Friday, July 26, 2019

Useful notes on Python

List
cats = ['Tommy', 'Snappy', 'Kitty', 'Jessie', 'Chester']

Print the third cat Kitty
print cats[2]

Print the first two cats Tommy and Snappy
print cats[0:2]

Add a new cat
cats.append('Princy')

Remove one cat entry: Jessie
del cats[3]

Dictionary
phonebook = {'Ashok': 408-111-1111, 'Bala': 408-222-2222, 'Chandra': 408-333-3333, 'Devaraj': 408-444-4444}

Add a new person
phonebook['Eswaran'] = 408-555-5555

Delete one person
del phonebook['Devaraj']

Tuple
days = ('Mon, 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')

No additions, deletions or modifications can be made to a tuple.

=======================================================================

A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern.
Example:
re.match(pattern, string, flags = 0)

=======================================================================










No comments:

Post a Comment