Data Type Flashcards
1
Q
Integers
A
- int
- Whole numbers, such as: 3 300 200
2
Q
Floating point
A
- float
- Numbers with a decimal pint: 2.3. 4.6. 100.0
3
Q
Strings
A
- str
- ordered sequence of characters: “hello” ‘Sammy’ “2000”
4
Q
Lists
A
- list
- Ordered sequence of objects: [10,”hello”,200.3]
- In brackets []
5
Q
Dictionaries
A
- dict
- In { }
- Unordered Key:Value pairs: {“mykey”:”value”,”name”:”Frankie”}
- thisdict = {“brand”: “Ford”, “model”: “Mustang”, “year”: 1964}
print(thisdict[“brand”])
6
Q
Tuples
A
- tup ( )
- thistuple = (“apple”, “banana”, “cherry”)
print(thistuple) - Ordered immutable sequence of objects: (10,”hello”,200.3)
7
Q
Sets
A
- 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.
8
Q
Booleans
A
- bool
- Logical value indicating True or False
9
Q
Text Type
A
str
10
Q
Numeric Types
A
- int
- float
- complex
11
Q
Sequence Types
A
- list
- tuple
- range
12
Q
Mapping Type
A
dict
13
Q
Set Types
A
- set
- frozenset
14
Q
Boolean Type
A
bool
15
Q
Binary Types
A
- bytes
- bytearray
- memoryview
16
Q
Brackets [] used for:
A
- List
- List comprehensions
17
Q
Braces {} used for:
A
- Sets eg. s1={10,20,30}
- Dictionary eg. d1={‘roll’:101, ‘name’:’xyz’}
18
Q
Parentheses() used for:
A
- Immutable sequenced data type (data that doesn’t change)
- t1=(10,20,30)
19
Q
- brackets []
- braces {}
- parenthese ()
A
- list
- sets
- tup
20
Q
- list
- sets
- tup
A
- brackets []
- braces {}
- parenthese ()
21
Q
Get the data type of any object:
A
- type()
- print(type(x))
22
Q
Setting the Data Type:
x = “Hello World”
A
str
23
Q
Setting the Data Type:
x = 20
A
int
24
Q
Setting the Data Type:
x = 20.5
A
float
25
Setting the Data Type:
x = 1j
complex
26
Setting the Data Type:
x = ["apple", "banana", "cherry"]
list
27
Setting the Data Type: x = ("apple", "banana", "cherry")
tuple
28
Setting the Data Type:
x = range(6)
range
29
Setting the Data Type:
x = {"name" : "John", "age" : 36}
dict
30
Setting the Data Type:
x = {"apple", "banana", "cherry"}
set
31
Setting the Data Type:
x = frozenset({"apple", "banana", "cherry"})
frozenset
32
Setting the Data Type:
x = True
bool
33
Setting the Data Type:
x = b"Hello"
bytes
34
Setting the Data Type:
x = bytearray(5)
bytearray