Python Unit-1 Notes
Introduction to Python
- Python ek high-level, interpreted, open-source programming language hai.
- Developer: Guido van Rossum, 1991.
- Syntax simple aur readable hai.
- Applications: Web Development, Data Science, AI, Automation, Software Development.
Why Python?
- Simple & Easy to learn
- Free & Open Source
- Platform Independent
- Vast library support (NumPy, Pandas, Matplotlib)
- Good readability
Features of Python
1. Interpreted Language → Line by line execute hoti hai.
2. Portable → Windows, Linux, Mac par chalega.
3. Dynamically Typed → Type runtime par decide hota hai.
4. Object Oriented → OOP concepts supported.
5. Extensive Libraries → Ready-made packages.
Disadvantages of Python
- Slower than C++/Java
- High memory consumption
- Limited for Mobile Apps & Enterprise DB
- Database handling limited
Python Installation
- Preferred version: Python 3
- Website: [Link]
- IDE: IDLE included with Python installation
- Run methods: GUI (IDLE, IDEs), Command line
Python Basics
Keywords
- 35 reserved words in Python 3.13
- Example: if, else, while, for, break, continue, True, False, None, def, class, return
Character Set
- Letters (A–Z, a–z), Digits (0–9), Special symbols, Whitespace, Unicode supported
Variables
- Variable ek name hai jo value store karta hai
- No explicit type declaration needed
Example:
x = 10 # int
y = "Raj" # str
z = 3.14 # float
Rules:
- Start with letter/underscore
- Cannot start with digit
- Case sensitive
Data Types
- int, float, complex, bool, str, list, tuple, set, dict
Python Blocks
- Defined by indentation (spaces), not {}
Operators in Python
1. Arithmetic: + - * / // % **
2. Assignment: = += -= *= /= //= %= **=
3. Relational: == != > < >= <=
4. Logical: and, or, not
5. Bitwise: & | ^ ~ << >>
6. Membership: in, not in
7. Identity: is, is not
Examples:
a = 10; b = 3
print(a+b) # 13
print(a//b) # 3
print(a**b) # 1000
Input in Python
- input() → returns string
name = input("Enter name: ")
age = int(input("Enter age: "))
Practice Questions
1. Input 2 numbers & print sum
2. Input side of square & print area
3. Input 2 float numbers & print average
4. Compare a >= b
5. Take name & print greeting
6. Find area of circle
7. Swap 2 numbers