Загрузка...

How python code works? What is Indentation in Python? #python #interview #job #shorts #youtubeshorts

🧱 Python Indentation – Brief Explanation

In Python, indentation means adding spaces or tabs at the beginning of a line to define the block of code.
Unlike other languages (like C, Java, or JavaScript) that use { } brackets, Python uses indentation to show which code belongs to which block (like inside if, for, while, function, etc.).

🧩 Why Indentation is Important

It tells Python which statements belong together.

Without correct indentation, your code will give an IndentationError.

It makes the code clean, readable, and structured.

✅ Example

x = 5
if x != 10:
print("x is not eaual to 10")
print("This line is inside the if block")

print("This line is outside the if block")
Explanation:
The two indented print() lines are part of the if block.
The last print() is not indented, so it runs outside the if block.

⚠️ Important Rules

Use the same number of spaces in the same block (recommended: 4 spaces per indentation level).

Don’t mix tabs and spaces — it causes errors.

Indentation defines scope — functions, loops, conditionals, and classes rely on it.

🧠 Example with Function

def greet():
print("Hello")
print("Welcome to Python!")

greet()
Here, both print statements are indented — they belong to the function greet().

💡 In Short

Indentation = Structure of Python Code

It tells Python where a block starts and ends.

Without proper indentation, Python won’t run your code.

Видео How python code works? What is Indentation in Python? #python #interview #job #shorts #youtubeshorts канала BhanuSharesTech
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять