Python Numbers

1. What are Numbers in Python?

Numbers are used to:

  • Count things

  • Do calculations

  • Solve math problems

Python supports different kinds of numbers.

2. Types of Numbers in Python

Python mainly has three types of numbers:

  1. Integer (int)

  2. Float (float)

  3. Complex (complex)

Beginners mostly use int and float.

3. Integer Numbers (int)

An integer is a whole number.
It has no decimal point.

Examples

age = 25
score = 100
temperature = -5
print(age)
print(score)
print(temperature)

4. Float Numbers (float)

A float is a number with a decimal point.

Examples

price = 19.99
pi = 3.14
height = 5.6
print(price)
print(pi)
print(height)

5. Complex Numbers (complex) (Basic Idea)

Complex numbers have:

  • a real part

  • an imaginary part

Example

x = 2 + 3j
print(x)

πŸ‘‰ Beginners usually don’t use this now.

6. Basic Math Operations with Numbers

Python can do all common math.

Addition

a = 10
b = 5
print(a + b)

Subtraction

print(a - b)

Multiplication

print(a * b)

Division

print(a / b)

7. Other Useful Number Operations

Power (Exponent)

print(2 ** 3) # 2 Γ— 2 Γ— 2

Modulus (Remainder)

print(10 % 3)

Floor Division

print(10 // 3)

8. Checking Number Type

Use type() to see number type.

Example

x = 10
y = 10.5
print(type(x))
print(type(y))

9. Converting Between Number Types

Integer to Float

a = 5
b = float(a)
print(b)

Float to Integer

x = 12.9
y = int(x)
print(y)

πŸ‘‰ Decimal part is removed.

10. Taking Number Input from User

Input is always text, so convert it.

Example

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(“Sum:”, a + b)

11. Common Beginner Mistakes

❌ Forgetting Conversion

num = input("Enter number: ")
print(num + 5)

βœ” Correct:

num = int(input("Enter number: "))
print(num + 5)

❌ Dividing Integers Expecting Integer

print(5 / 2)

Output:

2.5

Python always returns float for /.

12. Simple Practice Examples

Example 1: Simple Calculator

a = 20
b = 4
print(“Add:”, a + b)
print(“Subtract:”, a – b)
print(“Multiply:”, a * b)
print(“Divide:”, a / b)

Example 2: Area of Rectangle

length = 10
width = 5
area = length * width
print(“Area:”, area)

Example 3: Check Even or Odd

num = 7

if num % 2 == 0:
print(“Even number”)
else:
print(“Odd number”)

13. Summary (Python Numbers)

βœ” Python supports different numbers
βœ” int = whole number
βœ” float = decimal number
βœ” / gives decimal result
βœ” Convert input before math

πŸ“˜ Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Python Strings (easy)

  • Python Booleans

  • Operators

  • Number Exercises

  • MCQs with answers

Just tell me 😊

You may also like...