Unit 1: Introduction to Python
Why Python?
● High-level, interpreted, easy to learn.
● Dynamic typing & memory management.
● Widely used in data science, AI, web, and automation.
➔ Python is a high-level, interpreted programming language known for its simple
syntax, dynamic typing, and automatic memory management. It is easy to learn and
widely used in fields like data science, artificial intelligence, web development, and
automation.
Essential Python Libraries:
Library Purpose
math Math operations
random Random number generation
re Regular expressions
numpy Numerical computations (covered later)
pandas Data analysis
matplotlib, seaborn Data visualization
Data Types:
Type Example
Integer a = 10
Float pi = 3.14
String s = "hello"
Boolean flag = True
Complex z = 3 + 4j
Expressions and Operators:
Operator Type Operators Example Meaning
Arithmetic +-*/ a+b*c Addition, Subtraction,
Multiplication, Division
// % ** 10 // 3 = 3 Floor Division, Modulo
(Remainder), Power
Relational == != > < >= <= x > y, x == y Check values and relationships
Logical and or not x > 5 and y < 10 Combine multiple conditions
Assignment = += -= *= /= x += 5 (same as x = x + 5) Assign or update variable
values
Bitwise & ` ^ ~ << >>
● Bitwise Example
Identifiers:
● Variable/function names
● Must begin with a letter or _
● Cannot be Python keywords
➔ Identifiers are names used for variables or functions. They must start with a letter or
✅ ❌
underscore and cannot be Python keywords.
➔ Examples: name, _total Invalid: 2days, class, int, float
Reserved Words (Keywords):
● Reserved Words (Keywords) are special words in Python used for syntax and structure;
you cannot use them as variable names.
● Examples: if, else, while, for, True, False, def, import
Indentation:
● Indentation in Python is used to define code blocks (like inside if, for, def, etc.) and is
mandatory.
Comments:
● Comments in Python are used to explain code and are ignored during execution.
● Single-line:
○ # This is a comment
● Multi-line:
○ Use triple quotes ''' or """