Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Förståelse av Numeriska Typer | Nummer
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Datatyper i Python

bookFörståelse av Numeriska Typer

Numbers are everywhere in Python. You'll use two core numeric types most of the time: integers (int) for whole numbers and floating-point numbers (float) for decimals (including scientific notation like 1e-3).

Integer and Float Essentials

  • Integers (int): whole numbers such as -2, 0, 7, 456566. Python supports arbitrarily large integers;
  • Floats (float): decimal values such as 2.5, 3.14159, 2.71828, or scientific notation like 6.02e23;
  • Truthiness: 0 and 0.0 are False, any other int/float is True in boolean contexts.
123456
# Basic numeric literals (no type checks or conversions here) n_int = 42 n_float = 3.14 n_sci = 1e-3 # 0.001 print(n_int, n_float, n_sci)
copy

Writing Large Numbers Readably

Humans often write 1,000,000 or 1 000 000. Python doesn't allow commas or spaces inside numeric literals, use underscores for readability.

12
million = 1_000_000 print(million == 1000000) # True
copy
Note
Note

Floats are stored as binary fractions, tiny rounding differences are normal (e.g., 0.1 + 0.2 may not be exactly 0.3). You'll handle rounding and formatting later.

1. What is the type of 1e2?

2. Which literal is valid in Python code for one million?

3. Pick the true statement about int and float.

question mark

What is the type of 1e2?

Select the correct answer

question mark

Which literal is valid in Python code for one million?

Select the correct answer

question mark

Pick the true statement about int and float.

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. 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

Suggested prompts:

Can you explain more about how to use underscores in numbers?

What happens if I try to use commas or spaces in numeric literals?

How do I check the type of a number in Python?

bookFörståelse av Numeriska Typer

Svep för att visa menyn

Numbers are everywhere in Python. You'll use two core numeric types most of the time: integers (int) for whole numbers and floating-point numbers (float) for decimals (including scientific notation like 1e-3).

Integer and Float Essentials

  • Integers (int): whole numbers such as -2, 0, 7, 456566. Python supports arbitrarily large integers;
  • Floats (float): decimal values such as 2.5, 3.14159, 2.71828, or scientific notation like 6.02e23;
  • Truthiness: 0 and 0.0 are False, any other int/float is True in boolean contexts.
123456
# Basic numeric literals (no type checks or conversions here) n_int = 42 n_float = 3.14 n_sci = 1e-3 # 0.001 print(n_int, n_float, n_sci)
copy

Writing Large Numbers Readably

Humans often write 1,000,000 or 1 000 000. Python doesn't allow commas or spaces inside numeric literals, use underscores for readability.

12
million = 1_000_000 print(million == 1000000) # True
copy
Note
Note

Floats are stored as binary fractions, tiny rounding differences are normal (e.g., 0.1 + 0.2 may not be exactly 0.3). You'll handle rounding and formatting later.

1. What is the type of 1e2?

2. Which literal is valid in Python code for one million?

3. Pick the true statement about int and float.

question mark

What is the type of 1e2?

Select the correct answer

question mark

Which literal is valid in Python code for one million?

Select the correct answer

question mark

Pick the true statement about int and float.

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 1
some-alt