Python Data Types Flashcards

(28 cards)

1
Q

__________ can store data of different types, and different types can do different things.

A

Variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Text Data Type?

A

String (str)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three Numeric Data Types?

A

int, float, complex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the three Sequence Data Types?

A

list, tuple, range

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Mapping Data Type?

A

dict

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two Set Data Types?

A

set, frozenset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Boolean Data Type?

A

bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the three Binary Data Types?

A

bytes, bytearray, memoryview

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a None Type Data Type?

A

NoneType

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 8 Python built-in data types?

A

Text Type
Numeric Types
Sequence Types
Mapping Type
Set Types
Boolean Type
Binary Types
None Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

You can get the data type of any object by using the ____________ function:

A

type()

Example:
Print the data type of the variable x:

x = 5
print(type(x))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Get the Output and the Data Type:

x = “Hello World”

A

display x:

Code:
x = “Hello World”

print(x)

print(type(x))

Output:
Hello World
<class ‘str’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Get the Output and the Data Type:
x = 20

A

display x:

Code:
x = 20

print(x)

print(type(x))

Output:
20
<class ‘int’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Get the Output and the Data Type:
x = 20.5

A

display x:

Code:
x = 20.5

print(x)

print(type(x))

Output:
20.5
<class ‘float’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Get the Output and the Data Type:
x = 1j

A

display x:

Code:
x = 1j

print(x)

print(type(x))

Output:
lj
<class ‘complex’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Get the Output and the Data Type:
x = [“apple”, “banana”, “cherry”]

A

display x:

Code:
x = [“apple”, “banana”, “cherry”]

print(x)

print(type(x))

Output:
[‘apple’, ‘banana’, ‘cherry’]
<class ‘list’>

17
Q

Get the Output and the Data Type:
x = (“apple”, “banana”, “cherry”)

A

display x:

Code:
x = (“apple”, “banana”, “cherry”)

print(x)

print(type(x))

Output:
(‘apple’, ‘banana’, ‘cherry’)
<class ‘tuple’>

18
Q

Get the Output and the Data Type:
x = range(6)

A

display x:

Code:
x = range(6)

print(x)

print(type(x))

Output:
range(0, 6)
<class ‘range’>

19
Q

Get the Output and the Data Type:
x = {“name” : “John”, “age” : 36}

A

display x:

Code:
x = {“name” : “John”, “age” : 36}

print(x)

print(type(x))

Output:
{‘name’: ‘John’, ‘age’: 36}
<class ‘dict’>

20
Q

Get the Output and the Data Type:
x = {“apple”, “banana”, “cherry”}

A

display x:

Code:
x = {“apple”, “banana”, “cherry”}

print(x)

print(type(x))

Output:
{‘apple’, ‘cherry’, ‘banana’}
<class ‘set’>

21
Q

Get the Output and the Data Type:
x = frozenset({“apple”, “banana”, “cherry”})

A

display x:

Code:
x = frozenset({“apple”, “banana”, “cherry”})

print(x)

print(type(x))

Output:
frozenset({‘apple’, ‘banana’, ‘cherry’})
<class ‘frozenset’>

22
Q

Get the Output and the Data Type:
x = True

A

display x:

Code:
x = True

print(x)

print(type(x))

Output:
True
<class ‘bool’>

23
Q

Get the Output and the Data Type:
x = b”Hello”

A

display x:

Code:
x = b”Hello”

print(x)

print(type(x))

Output:
b’Hello’
<class ‘bytes’>

24
Q

Get the Output and the Data Type:
x = bytearray(5)

A

display x:

Code:
x = bytearray(5)

print(x)

print(type(x))

Output:
bytearray(b’\x00\x00\x00\x00\x00’)
<class ‘bytearray’>

25
Get the Output and the Data Type: x = memoryview(bytes(5))
Code: x = memoryview(bytes(5)) #display x: print(x) #display the data type of x: print(type(x)) Output:
26
Get the Output and the Data Type: x = None
Code: x = None #display x: print(x) #display the data type of x: print(type(x)) Output: None
27
If you want to specify the data type, you can use ______________ functions.
constructor
28
If you want to specify the data type, you can use constructor functions. Give the 14 examples and then after it give the sample code on how to generate the output.
x = str("Hello World") x = int(20) x = float(20.5) x = complex(1j) x = list(("apple", "banana", "cherry")) x = tuple(("apple", "banana", "cherry")) x = range(6) x = dict(name="John", age=36) x = set(("apple", "banana", "cherry")) x = frozenset(("apple", "banana", "cherry")) x = bool(5) x = bytes(5) x = bytearray(5) x = memoryview(bytes(5)) Sample Code: x = str("Hello World") #display x: print(x) #display the data type of x: print(type(x)) Output: Hello World