Wednesday, 25 June 2025

Expressions and Numerical Types in Python

Expressions and Numerical Types in Python

📌 What is an Expression?

An expression is a combination of values, variables, and operators that Python can calculate (or evaluate) and give a result.

Example:

5 + 3
  • 👉 This is an expression. It combines two numbers and a plus sign.
  • 👉 The result of this expression is 8.
x = 10
y = x + 5
  • 👉 Here, x + 5 is an expression.
  • 👉 Python will calculate it and store 15 in y.

🧮 What are Numerical Types?

In Python, numbers come in different types based on how they are used.

There are mainly three types of numbers in Python:

1. int – Integer

These are whole numbers. They don't have any decimal point.

a = 5       # integer
b = -100    # negative integer

2. float – Floating Point Number

These are numbers with decimal points.

x = 3.14     # float
y = -0.5     # negative float

3. complex – Complex Numbers

These numbers have a real and an imaginary part.
Used mostly in higher math and science.

z = 2 + 3j   # complex number

You can check the type using type():

print(type(10))       # <class 'int'>
print(type(3.5))      # <class 'float'>
print(type(2 + 3j))   # <class 'complex'>

➕ Arithmetic Operators in Python

Python can do basic math using operators. These are:

Operator Meaning Example Result
+ Addition 5 + 3 8
- Subtraction 7 - 2 5
* Multiplication 4 * 3 12
/ Division 10 / 2 5.0
// Floor Division 10 // 3 3
% Modulus (remainder) 10 % 3 1
** Power 2 ** 3 8

✅ Summary

  • An expression is a combination of numbers, variables, and operators.
  • int, float, and complex are the 3 main number types in Python.
  • Python supports all basic math operations like +, -, *, /, %, etc.
  • Python follows the BODMAS rule for solving expressions.
  • You can use functions like abs(), round(), pow() with numbers.

No comments:

Post a Comment

Total Pageviews

Search This Blog

Write a program which performs the following operations using a simple queue. : insert() -> delete() -> display()

Write a program which performs the following operations using a simple queue. : insert() -> delete() -> display() ...