Data Types (Cheatsheet)
Data Types (Cheatsheet)
5: Dictionaries
Variables
A variable is a name associated with a value. It can be named anything, but
Correct Incorrect
Strings
A string is a sequence of characters surrounded by quotation marks: single
quotes '' or double quotes ""
Correct
Incorrect
Integers
An integer is a whole number of any Examples
length that can be positive or negative, -1 0 1 86400
written without a fractional element.
Floats
A float is a number that can be positive Examples
or negative written with a fractional -100.54 1.0 59.1
element.
Booleans
One of two values: True and False .
Extra Resources
What are variables
Strings and number
String formattin
Strings, Variables, and Getting Input from Users
Lists
An ordered, sequential data type
Used to store multiple elements in one variable
Defined by using a pair of square brackets.
Each element in a list has a position (index) through which it can be accessed.
Extra Resources
What is a list
Split, join, and slice
Extending Python lists
Tuples
Similar to lists, but are immutable
Defined by separating multiple values with commas
For better readability, it can be surrounded by parentheses (brackets).
Sets
An unordered data type
Elements cannot be accessed by their indices
Defined by using a pair of curly braces.
Extra Resources
Basic Python collection
Sets - 30 Days of Pytho
Python set operators
Dictionaries
Defined with 3 key components: curly braces, keys, and values
Keys must be strings or other hashable values
Values associated to each key can be anything
Dictionaries can be defined in one line:
Extra Resources
What is a dictionary
Updating Python dictionaries