Python Programming – Unit I & II Notes
UNIT I: Introduction to Python
Introduction and Basics: Python is a high-level, interpreted, object-oriented programming language
known for its simple syntax, portability, and dynamic typing.
Setting up Path: After installation, set the PATH environment variable so Python can run from any
directory. Example: C:\Python311\Scripts\
Variables & Operators: Variables store data. No type declaration needed. Data types include int, float,
str, bool, list, tuple, set, dict.
Operators: Arithmetic (+, -, *, /), Comparison (==, !=), Logical (and, or, not), Assignment (=, +=),
Membership (in, not in), Identity (is, is not).
id() and type(): id() returns memory address, type() returns data type.
Coding Standards: Follow PEP8 — meaningful names, indentation (4 spaces), comments,
lowercase_with_underscores for names.
Input-Output: print() for output, input() for input. Example: name = input("Enter name: ")
Control Structures: if-elif-else, nested if, loops (for, while). Use break (exit loop), continue (skip), pass
(placeholder).
UNIT II: String Manipulation, Lists and Tuples
String Manipulation: Strings are sequences of characters. Operations include concatenation (+),
repetition (*), and slicing (s[0:5]).
Common methods: upper(), lower(), title(), strip(), replace(), split(), find(), count().
Lists: Ordered, mutable collections. Example: fruits = ["apple", "banana"].
Access elements using index, perform operations like append(), remove(), sort(), reverse().
Tuples: Ordered, immutable sequences. Example: t = (10, 20, 30).
Operations: len(t), max(t), min(t), count(), index(). Can convert between lists and tuples.
Summary: Python provides simple syntax, dynamic typing, and versatile structures like strings, lists,
and tuples for effective programming.