02 Lesson Type Conversion

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Type Conversion

• More about formatted strings


• Types are not the same
• Convert them with int(), float(), str()
name = input("What is your name? ")
print(f"Hello {name}!")
birth_year = input("What is your birht year? ")
print(f"You were born in {birth_year}.")

Hello Rune!
You were born in 1990.

name = input("What is your name? ")


print(f"Hello {name}!")
birth_year = input("What is your birht year? ")
print(f"You are {2021 - birth_year} old!")

type(birth_year)

str

int(birth_year)

1990

name = input("What is your name? ")


print(f"Hello {name}!")
birth_year = input("What is your birht year? ")
birth_year = int(birth_year)
print(f"You are {2021 - birth_year} old!")

Hello Rune!
You are 31 old!

int("30")

30

int(" -4")

-4

float("2")

2.0

float("3.14")
3.14

float(3)

3.0

s = "This is a string"
i = 7

s + i

s + str(i)

'This is a string7'

You might also like