Data Types
Data types tell you what kind of value you have.
Common Types
-
int: whole numbers, like
0,-7,42 -
float: decimal numbers, like
3.14,-0.5 -
str: text in quotes, like
"hello"or'CS' -
bool:
TrueorFalse
Examples
age = 17 # int
gpa = 3.8 # float
name = "Riley" # str
is_student = True # bool
Check a Type
type(42) # <class 'int'>
type("hi") # <class 'str'>
Convert Between Types
int("7") # 7
float("2.5") # 2.5
str(100) # "100"
Note: converting a non-number string like int("hi") causes an error.
⠀