Concept
Converting Types (int, float, str)
Convert data between types with `int()`, `float()`, and `str()`:
python
x = int("50") # Text "50" becomes real number 50
y = str(100) # Number 100 becomes text "100"
z = float("3.14") # Text "3.14" becomes float 3.14
# 21. Converting Types (int, float, str) Convert data between types with `int()`, `float()`, and `str()`: ```python x = int("50") # Text "50" becomes real number 50 y = str(100) # Number 100 becomes text "100" z = float("3.14") # Text "3.14" becomes float 3.14 ``` Warning: Feeding non-numeric junk into `int("tacos")` crashes with an angry `ValueError`. Python won't guess your intentions.
Checkpoint
What happens if you run `int("pizza")`?
Practice
You have `price_text = "49"`. Convert it to a real integer and add `1` to it. Print the answer `50`.
01
Tap code blocks below to assemble
Available Blocks