FROM YOUR LOVE PURU, AKKU BABES 😘
PYTHON PROGRAMMING – DETAILED BEGINNER
NOTES
INTRODUCTION TO PYTHON
Python is a high-level, interpreted, and general-purpose programming language. It is used to
communicate with computers and give instructions to perform different tasks such as calculations, data
processing, decision making, and data visualization.
Python is very popular because it is easy to learn, has simple English-like syntax, and is widely used
in areas such as data analysis, web development, artificial intelligence, machine learning, and
automation.
Python was created by Guido van Rossum and released in 1991.
Features of Python:
• Easy to read and write
• Free and open source
• Platform independent
• Large standard library
• Supports object-oriented programming
• Widely used in data science and analytics
PART A: PARTS OF PYTHON PROGRAMMING LANGUAGE
PART A: PARTS OF PYTHON PROGRAMMING LANGUAGE
1. IDENTIFIERS
Identifiers are the names used to identify variables, functions, classes, or objects in a Python
program.
Rules for identifiers:
• Must start with a letter (A–Z or a–z) or underscore (_)
• Cannot start with a digit
• Cannot use Python keywords
• No spaces allowed
• Case-sensitive
1
Examples:
name = "Python"
age = 21
_total = 100
Invalid identifiers:
1name
class
my name
2. KEYWORDS
Keywords are reserved words that have predefined meaning in Python. They cannot be used as
identifiers.
Examples:
if, else, elif, for, while, break, continue
def, return, True, False, None, import
3. STATEMENTS AND EXPRESSIONS
• Statement: A complete instruction that performs an action.
• Expression: A combination of values, variables, and operators that produces a result.
Example:
x = 10 + 5 # statement
10 + 5 # expression
4. VARIABLES, OPERATORS, PRECEDENCE AND ASSOCIATIVITY
Variables:
Variables are used to store data in memory.
Example:
2
x = 10
name = "Alex"
Operators:
Arithmetic operators:
+ - * / % ** //
Relational operators:
== != > < >= <=
Logical operators:
and or not
Operator precedence:
Defines which operator is evaluated first.
Example:
result = 10 + 2 * 3
Multiplication is performed first → Output = 16.
5. DATA TYPES
Data types define the type of data stored in a variable.
Common data types: - int → whole numbers - float → decimal numbers - str → text - bool → True or
False
Example:
a = 10
b = 3.5
c = "Python"
d = True
3
6. INDENTATION, COMMENTS, INPUT, OUTPUT, TYPE CONVERSION
Indentation:
Python uses indentation to define code blocks.
if a > 0:
print("Positive")
Comments:
Used to explain code.
# This is a comment
Reading input:
name = input("Enter name: ")
age = int(input("Enter age: "))
Printing output:
print("Hello", name)
Type conversion:
int("10")
float("3.5")
str(100)
7. type() FUNCTION, is OPERATOR, DYNAMIC AND STRONGLY TYPED LANGUAGE
type() function:
Used to check the data type of a variable.
x = 10
print(type(x))
4
is operator:
Checks whether two variables refer to the same object.
a = 10
b = 10
print(a is b)
Dynamic typing:
Type is decided at runtime.
Strong typing:
Python does not allow mixing incompatible types automatically.
8. DECISION CONTROL FLOW STATEMENTS
Used to make decisions.
if marks >= 60:
print("Pass")
else:
print("Fail")
9. LOOP STATEMENTS, CONTINUE AND BREAK
for loop:
for i in range(5):
print(i)
while loop:
i = 1
while i <= 5:
print(i)
i += 1
break statement:
Stops the loop.
5
continue statement:
Skips current iteration.
PART B: STRINGS AND LISTS
10. STRINGS
A string is a sequence of characters enclosed in quotes.
Creating strings:
s = "Python"
Basic string operations:
s + " Language"
s * 3
Accessing characters by index:
s[0]
s[-1]
String slicing:
s[1:4]
s[:3]
s[::2]
String joining:
" ".join(["Hello", "World"])
String methods:
[Link]()
[Link]()
[Link]("P", "J")
6
Formatting strings:
name = "Alex"
print(f"Hello {name}")
11. LISTS
A list stores multiple values in one variable.
nums = [1, 2, 3]
Basic operations:
[Link](4)
[Link](2)
PART C: FUNCTIONS
12. FUNCTIONS
A function is a block of reusable code.
Built-in functions:
len(), type(), sum(), max(), min()
Commonly used modules:
import math
import random
Function definition and calling:
def add(a, b):
return a + b
add(2, 3)
7
Return statement and void function:
Functions without return are void.
Scope and lifetime of variables:
• Local variables exist inside functions
• Global variables exist outside functions
Default parameters:
def power(x, y=2):
return x ** y
Keyword arguments:
add(b=5, a=3)
args and *kwargs:
def total(*nums):
return sum(nums)
Command line arguments:
Arguments passed while running program from terminal.
PART D: TUPLES AND SETS
13. TUPLES
Tuples are ordered and immutable collections.
t = (1, 2, 3)
Indexing and slicing:
t[0]
t[1:]
Built-in functions:
8
len(t)
max(t)
Relation between tuples and lists: Lists are mutable, tuples are immutable.
Relation between tuples and dictionaries: Tuples can be dictionary keys.
Tuple methods:
[Link](1)
[Link](2)
zip() function:
list(zip([1,2],[3,4]))
14. SETS
Sets store unique values.
s = {1, 2, 3}
Set methods:
[Link](4)
[Link](2)
Traversing sets:
for i in s:
print(i)
Frozen set: An immutable set.
PART E: ANALYSIS USING PANDAS AND NUMPY
9
15. INTRODUCTION TO PANDAS
Pandas is used for data analysis and data manipulation.
Use cases: - Data cleaning - Handling missing values - Data analysis
Pandas data structures:
• Series (1D)
• DataFrame (2D)
Example:
import pandas as pd
data = {"Name": ["A", "B"], "Marks": [80, 90]}
df = [Link](data)
Experimenting with Pandas functions:
[Link]()
[Link]()
16. INTRODUCTION TO NUMPY
NumPy is used for numerical and scientific computing.
Importance of NumPy: - Faster computations - Multi-dimensional arrays
NumPy array:
import numpy as np
arr = [Link]([1, 2, 3])
N-dimensional array:
arr2 = [Link]([[1, 2], [3, 4]])
Specific NumPy functions:
[Link](arr)
[Link](arr)
10
PART F: DATA VISUALIZATION ECOSYSTEM IN PYTHON
17. DATA VISUALIZATION ECOSYSTEM
Data visualization means representing data using charts and graphs.
Dynamic graphs:
Graphs that allow interaction.
Plotly:
Plotly is a Python library used to create interactive graphs.
Three structures of Plotly: - Plotly Express - Graph Objects - Dash
Creating plots using Plotly:
import [Link] as px
df = [Link]()
fig = [Link](df, x="sepal_width", y="sepal_length")
[Link]()
Interactive elements:
• Dropdowns
• Buttons
• Sliders
• Selectors
These elements allow user interaction with data.
11