🔰 Python Syntax Dive(PART-1)
🔹 1. Variables and Data Types in Python
✅ Theory
● Variable: A container used to store data values.
● In Python, you don't need to declare the data type explicitly —
Python detects it based on the assigned value (this is called
dynamic typing).
● Data types refer to the kind of value a variable can hold, such as
a number, text, or Boolean.
🔹 2. Input and Output in Python
✅ Theory
🟩 Input (input())
● input() is used to take user input from the keyboard.
● It always returns a string, so you often need to convert it to
another type (int, float, etc.).
🟦 Output (print())
● print() is used to display output to the console.
● You can print strings, numbers, variables, expressions, etc.
● Supports formatting like print(f"Hello {name}").
🔹 3. Conditional Statements in Python
✅ Theory
Conditional statements allow a program to make decisions based on
certain conditions.
🟩 Keywords Used:
● if → Executes block if condition is true
● elif → Checks another condition if previous was false
● else → Executes block if none of the above conditions are true
🔹 Syntax Structure
✳️ Example 1: Simple if
✳️ Example 2: if-else
✳️ Example 3: if-elif-else
✳️ Example 4: Nested if
🔹 4. Loops in Python (for, while)
✅ Theory
Loops allow you to execute a block of code multiple times.
Python supports two main types of loops:
🟦 for loop
● Used to iterate over a sequence (like list, string, range, etc.).
🟩 while loop
● Repeats as long as a condition is True.
🔁 Loop Control Statements
● break – Exit the loop immediately.
● continue – Skip the current iteration.
● pass – Do nothing (used as a placeholder).
✳️ Example 1: for loop with range()
✳️ Example 2: while loop
✳️ Example 3: for loop with a list
✳️ Example 4: while loop with break and continue
🔹 5. Functions in Python
✅ Theory
A function is a reusable block of code that
performs a specific task. It helps you:
● Avoid code repetition
● Improve readability
● Organize logic into chunks
🟩 Function Types
Built-in functions (e.g., print(), len(), range())
User-defined functions (you create these with def
keyword)
🟦 Function Syntax
✳️ Example 1: Basic Function (No Parameters)
✳️ Example 2: Function with Parameters
✳️ Example 3: Function with Return Value
✳️ Example 4: Function with Default Parameter