Python Data Types Flashcards
(28 cards)
__________ can store data of different types, and different types can do different things.
Variables
What is a Text Data Type?
String (str)
What are the three Numeric Data Types?
int, float, complex
What are the three Sequence Data Types?
list, tuple, range
What is the Mapping Data Type?
dict
What are the two Set Data Types?
set, frozenset
What is a Boolean Data Type?
bool
What are the three Binary Data Types?
bytes, bytearray, memoryview
What is a None Type Data Type?
NoneType
What are the 8 Python built-in data types?
Text Type
Numeric Types
Sequence Types
Mapping Type
Set Types
Boolean Type
Binary Types
None Type
You can get the data type of any object by using the ____________ function:
type()
Example:
Print the data type of the variable x:
x = 5
print(type(x))
Get the Output and the Data Type:
x = “Hello World”
display x:
Code:
x = “Hello World”
print(x)
print(type(x))
Output:
Hello World
<class ‘str’>
Get the Output and the Data Type:
x = 20
display x:
Code:
x = 20
print(x)
print(type(x))
Output:
20
<class ‘int’>
Get the Output and the Data Type:
x = 20.5
display x:
Code:
x = 20.5
print(x)
print(type(x))
Output:
20.5
<class ‘float’>
Get the Output and the Data Type:
x = 1j
display x:
Code:
x = 1j
print(x)
print(type(x))
Output:
lj
<class ‘complex’>
Get the Output and the Data Type:
x = [“apple”, “banana”, “cherry”]
display x:
Code:
x = [“apple”, “banana”, “cherry”]
print(x)
print(type(x))
Output:
[‘apple’, ‘banana’, ‘cherry’]
<class ‘list’>
Get the Output and the Data Type:
x = (“apple”, “banana”, “cherry”)
display x:
Code:
x = (“apple”, “banana”, “cherry”)
print(x)
print(type(x))
Output:
(‘apple’, ‘banana’, ‘cherry’)
<class ‘tuple’>
Get the Output and the Data Type:
x = range(6)
display x:
Code:
x = range(6)
print(x)
print(type(x))
Output:
range(0, 6)
<class ‘range’>
Get the Output and the Data Type:
x = {“name” : “John”, “age” : 36}
display x:
Code:
x = {“name” : “John”, “age” : 36}
print(x)
print(type(x))
Output:
{‘name’: ‘John’, ‘age’: 36}
<class ‘dict’>
Get the Output and the Data Type:
x = {“apple”, “banana”, “cherry”}
display x:
Code:
x = {“apple”, “banana”, “cherry”}
print(x)
print(type(x))
Output:
{‘apple’, ‘cherry’, ‘banana’}
<class ‘set’>
Get the Output and the Data Type:
x = frozenset({“apple”, “banana”, “cherry”})
display x:
Code:
x = frozenset({“apple”, “banana”, “cherry”})
print(x)
print(type(x))
Output:
frozenset({‘apple’, ‘banana’, ‘cherry’})
<class ‘frozenset’>
Get the Output and the Data Type:
x = True
display x:
Code:
x = True
print(x)
print(type(x))
Output:
True
<class ‘bool’>
Get the Output and the Data Type:
x = b”Hello”
display x:
Code:
x = b”Hello”
print(x)
print(type(x))
Output:
b’Hello’
<class ‘bytes’>
Get the Output and the Data Type:
x = bytearray(5)
display x:
Code:
x = bytearray(5)
print(x)
print(type(x))
Output:
bytearray(b’\x00\x00\x00\x00\x00’)
<class ‘bytearray’>