Get Started & Syntax
Python is a readable, high-level language. Unlike C++ or Java, it handles memory management for you and emphasizes code readability.
Indentation is Semantics
In many languages (JS, C++), indentation is just for style. In Python, **indentation is logic**. It defines the scope of loops, functions, and classes. If you mess up whitespace, your code crashes (`IndentationError`).
if 5 > 2:
print("Inside the if-block") # Indented
print("Outside the if-block") # UnindentedPro Tip
Standard convention is 4 spaces. Do not mix tabs and spaces. In interviews, consistency matters more than width.
Comments & Docstrings
Comments (`#`) are ignored by the interpreter. **Docstrings** (`"""`) are retained at runtime and are used for documentation generation. Use docstrings for functions/classes to explain *what* they do (Input/Output), and comments to explain *why* complex logic exists.
def add(a, b):
"""
Adds two numbers and returns the result.
Input: int/float
Output: int/float
"""
# We don't validate types here for performance reasons
return a + bThe 'Pass' Keyword
Python requires blocks (like `if`, `def`, `class`) to not be empty. If you are sketching out code or defining an abstract interface, use `pass` as a placeholder.
def implementation_later():
pass # Prevents SyntaxError