Python Notes
Introduction to Python
Python is a high-level, interpreted programming language known for its simple syntax,
readability, and versatility. It supports multiple programming styles, including object-
oriented, functional, and procedural.
Key Features of Python
Easy Syntax: Code is clean and easy to read.
Interpreted & Dynamically Typed: Code is executed line-by-line, and variable types are
detected automatically.
Extensive Standard Libraries: Comes with a large collection of pre-built modules for
various tasks.
Cross-Platform: Runs on Windows, macOS, Linux, and other operating systems.
Large Community: Strong community support for help and third-party packages.
Part 1: Python Fundamentals
1. Variables and Data Types
A variable is a container for storing data values. Python is dynamically typed, meaning it
automatically detects the data type of a variable.
String (str): Textual data enclosed in quotes. Example: message = "Hello, World"
Integer (int): Whole numbers. Example: count = 42
Float (float): Numbers with a decimal point. Example: price = 19.99
Boolean (bool): Represents True or False. Example: is_active = True
List (list): Ordered and mutable collection. Example: fruits = ["apple", "banana",
"cherry"]
Tuple (tuple): Ordered and immutable collection. Example: coordinates = (10.5, 20.7)
Set (set): Unordered collection of unique elements. Example: {"red", "green", "blue"}
Dictionary (dict): Key-value pairs. Example: person = {"name": "Alice", "age": 25}
2. Operators in Python
Operators are symbols used to perform operations on variables and values.
Arithmetic, Comparison, Logical, and Assignment operators are
commonly used.
Part 2: Common Data Structures and Their Methods
Includes Strings, Lists, and Dictionaries with various built-in methods.
Part 3: Essential Built-in Functions
Examples: len(), type(), range(), enumerate(), zip(), map(), filter(), sorted(), any(), all().
Part 4: Common Code Snippets & Patterns
Examples include reversing strings, palindrome checks, flattening lists, Fibonacci, factorial,
etc.
Part 5: Important Python Concepts
*args and **kwargs: Used for variable-length arguments in functions.
Shallow Copy vs Deep Copy: Difference in reference vs independent copy.
is vs ==: Identity vs value equality.
Modules and Packages: Single Python files vs directories of modules.