Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Grundläggande Typkonvertering | Interaktioner Mellan Olika Datatyper
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Datatyper i Python

bookGrundläggande Typkonvertering

123456
age_input = " 42 " print(int(age_input)) # 42 print(int(2.9)) # 2 print(int(-2.9)) # -2 print(int("7")) # 7 print(int(" -15 ")) # -15
copy
12
int("2.5") # ValueError - not an integer string int("42a") # ValueError
copy
123
print(float(3)) # 3.0 print(float("2.5")) # 2.5 print(float("1e3")) # 1000.0
copy
1
float("2,5") # ValueError - use a dot, not a comma
copy
123
print(str(42)) # "42" print(str(3.5)) # "3.5" print(f"Ada scored {98} points.")
copy
12345
print(bool(0)) # False print(bool(7)) # True print(bool("")) # False print(bool("0")) # True print(bool("False")) # True
copy
question mark

Select the correct answer

question mark

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 1

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

bookGrundläggande Typkonvertering

Svep för att visa menyn

123456
age_input = " 42 " print(int(age_input)) # 42 print(int(2.9)) # 2 print(int(-2.9)) # -2 print(int("7")) # 7 print(int(" -15 ")) # -15
copy
12
int("2.5") # ValueError - not an integer string int("42a") # ValueError
copy
123
print(float(3)) # 3.0 print(float("2.5")) # 2.5 print(float("1e3")) # 1000.0
copy
1
float("2,5") # ValueError - use a dot, not a comma
copy
123
print(str(42)) # "42" print(str(3.5)) # "3.5" print(f"Ada scored {98} points.")
copy
12345
print(bool(0)) # False print(bool(7)) # True print(bool("")) # False print(bool("0")) # True print(bool("False")) # True
copy
question mark

Select the correct answer

question mark

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 1
some-alt