loading...

Charming the Python: Data Structures

vickilanger profile image Vicki (she/her) Updated on ・1 min read

If coding tutorials with math examples are the bane of your existence, keep reading. This series uses relatable examples like dogs and cats.


Quick Bits on Python Data Structures

Strings

# Syntax
'string'
"string"
'''string'''
"""string"""

Lists

  • multiple data types
  • mutable/changeable
  • ordered
  • indexed
# Syntax
list_name = ['list item 1', 'list item 2', 'list item 3']

Tuples

  • multiple data types
  • immutable/unchangeable
  • ordered
  • indexed
# Syntax
dogs = ('chihuahua', 'golden retriever', 'german shepherd', 'mutt')

Sets

  • unordered
  • no index
  • mutable/changeable
# Syntax
dog_parts = {'paws', 'legs', 'tail', 'fur'}

Dictionaries

  • key/value pairs
  • mutable/changeable
# syntax
dogs = {
    'name': 'Cheeto',
    'colors': ['tan', 'black'],
    'age': 4.5,
    'chipped': True,
    'breed': 'chihuahua',
    'weight': 12.8,
    'vaccines_due':{
        'rabies': 2022,
        'dhpp': 2020,
        'kennel_cough': 2020,
    }
    }

Posted on by:

vickilanger profile

Vicki (she/her)

@vickilanger

Vicki was once a manager of aircraft maintenance and is now charming Python. She coded #VetsWhoCode bot & Code Questions bot. When Vicki isn't petting her cat, she’s throwing a ball for her dogs.

Discussion

pic
Editor guide