Data Type Flashcards
Integers
- int
- Whole numbers, such as: 3 300 200
Floating point
- float
- Numbers with a decimal pint: 2.3. 4.6. 100.0
Strings
- str
- ordered sequence of characters: “hello” ‘Sammy’ “2000”
Lists
- list
- Ordered sequence of objects: [10,”hello”,200.3]
- In brackets []
Dictionaries
- dict
- In { }
- Unordered Key:Value pairs: {“mykey”:”value”,”name”:”Frankie”}
- thisdict = {“brand”: “Ford”, “model”: “Mustang”, “year”: 1964}
print(thisdict[“brand”])
Tuples
- tup ( )
- thistuple = (“apple”, “banana”, “cherry”)
print(thistuple) - Ordered immutable sequence of objects: (10,”hello”,200.3)
Sets
- Braces {}
- set
- myset = {“apple”, “banana”, “cherry”}
- Unordered collection of unique objects: {“a”,”b”}
- Note: Set items are unchangeable, but you can remove items and add new items.
Booleans
- bool
- Logical value indicating True or False
Text Type
str
Numeric Types
- int
- float
- complex
Sequence Types
- list
- tuple
- range
Mapping Type
dict
Set Types
- set
- frozenset
Boolean Type
bool
Binary Types
- bytes
- bytearray
- memoryview
Brackets [] used for:
- List
- List comprehensions
Braces {} used for:
- Sets eg. s1={10,20,30}
- Dictionary eg. d1={‘roll’:101, ‘name’:’xyz’}
Parentheses() used for:
- Immutable sequenced data type (data that doesn’t change)
- t1=(10,20,30)
- brackets []
- braces {}
- parenthese ()
- list
- sets
- tup
- list
- sets
- tup
- brackets []
- braces {}
- parenthese ()
Get the data type of any object:
- type()
- print(type(x))
Setting the Data Type:
x = “Hello World”
str
Setting the Data Type:
x = 20
int
Setting the Data Type:
x = 20.5
float
Setting the Data Type:
x = 1j
complex
Setting the Data Type:
x = [“apple”, “banana”, “cherry”]
list
Setting the Data Type: x = (“apple”, “banana”, “cherry”)
tuple
Setting the Data Type:
x = range(6)
range
Setting the Data Type:
x = {“name” : “John”, “age” : 36}
dict
Setting the Data Type:
x = {“apple”, “banana”, “cherry”}
set
Setting the Data Type:
x = frozenset({“apple”, “banana”, “cherry”})
frozenset
Setting the Data Type:
x = True
bool
Setting the Data Type:
x = b”Hello”
bytes
Setting the Data Type:
x = bytearray(5)
bytearray