DEV Community

Vicki Langer
Vicki Langer

Posted on • Edited on

Charming the Python: Data Structures

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"""
Enter fullscreen mode Exit fullscreen mode

Lists

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

Tuples

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

Sets

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

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,
    }
    }

Enter fullscreen mode Exit fullscreen mode

Top comments (0)