data sets Flashcards
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
None Type:
NoneType
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
None Type:
NoneType
You can get the data type of any object by using the?
type()
x = 5
print(type(x))
A whole number, positve or negative
int
is a number, positive or negative, containing one or more decimals, can also be scientific numbers with an “e” to indicate the power of 10
float
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))
x = 35e3
y = 12E4
z = -87.7e100
print(type(x))
print(type(y))
print(type(z))
numbers are written with a “j” as the imaginary part:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
How can you convert one type to another with the int(), float(), and complex() methods:
convert from int to float:
x = 1 # int
y = 2.8 # float
z = 1j # complex
a = float(x)
b = int(y)
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
but Python has a built-in module called ? that can be used to make auto output numbers:
random()
“”””
import random
print(random.randrange(1, 10))
“””