Detailed Python Programming Notes (Module Wise)
1) Tokens in Python (5 Marks)
Definition:
Tokens are the smallest individual units in a Python program. Python programs are made up of different types of
tokens.
Types of Tokens:
1. Keywords
Keywords are reserved words in Python that have special meanings.
Examples: if, else, while, for, break, continue, return.
Example: if True:
print("Hello")
2. Identifiers
Identifiers are names used for variables, functions, and classes.
Example: name = "Anan"
Rules: • Cannot start with a number
• Cannot use keywords
• Case-sensitive
3. Literals
Literals are fixed values used in programs.
Examples: • Numeric literal → 10, 3.14
• String literal → "Python"
• Boolean literal → True, False
4. Operators
Operators perform operations on values.
Examples: +, -, *, /, %, ==
5. Delimiters / Symbols
Symbols used to separate statements and expressions.
Examples: (), {}, [], :, ;, ,
2) Data Types in Python (5 Marks)
Definition:
Data types specify the type of data stored in a variable.
Types of Data Types:
1. Integer (int)
Stores whole numbers.
Example: x = 10
2. Float
Stores decimal numbers.
Example: y = 3.14
3. Complex
Stores complex numbers.
Example: z = 2+3j
4. String
Stores sequence of characters.
Example: name = "Python"
5. List
Ordered and mutable collection.
Example: numbers = [1,2,3]
6. Tuple
Ordered and immutable collection.
Example: t = (10,20,30)
7. Set
Unordered collection of unique values.
Example: s = {1,2,3}
8. Dictionary
Stores key-value pairs.
Example: student = {"name":"Anan","age":20}
9. Boolean
Represents True or False.
Example: x = True
3) Types of Arguments in Python (5 Marks)
Definition:
Arguments are values passed to functions during function calls.
1. Positional Arguments
Arguments passed according to position.
Example: def add(a,b):
print(a+b)
add(10,20)
2. Keyword Arguments
Arguments passed using parameter names.
Example: student(name="Anan", age=20)
3. Default Arguments
Arguments with default values.
Example: def greet(name="User"):
print(name)
4. Variable Length Arguments
Used to pass multiple values.
Example: def total(*n):
print(sum(n))
4) Types of Functions in Python (5 Marks)
Definition:
Functions are reusable blocks of code used to perform tasks.
1. Built-in Functions
Functions already available in Python.
Examples: print(), len(), input()
2. User-defined Functions
Functions created by programmers.
Example: def add(a,b):
return a+b
3. Recursive Functions
Functions that call themselves.
Example: def fact(n):
if n==1:
return 1
return n*fact(n-1)
4. Anonymous (Lambda) Functions
Functions without names.
Example: square = lambda x:x*x
5. Functions Returning Multiple Values
Example: def values():
return 10,20
5) String Operations in Python (5 Marks)
Definition:
A string is a sequence of characters enclosed in quotes.
1. String Slicing
Used to extract part of a string.
Syntax: string[start:end]
Example: text = "Python"
print(text[0:3])
2. String Traversal
Accessing characters one by one.
Example: for ch in "Python":
print(ch)
3. String Splitting
Converts string into list.
Example: text = "Python is easy"
print([Link]())
4. String Joining
Combines list elements into a string.
Example: words = ['Python','is','easy']
print(" ".join(words))
6) Explain Any 5 Built-in Functions in Python (5 Marks)
1. print()
Used to display output.
Example: print("Hello")
2. input()
Used to get input from user.
Example: name = input("Enter Name: ")
3. len()
Returns length of object.
Example: len("Python")
4. type()
Returns datatype of variable.
Example: type(10)
5. sum()
Returns sum of elements.
Example: sum([1,2,3])
7) What is Module in Python? (2 Marks)
A module is a file containing Python code such as variables, functions, and classes.
Advantages:
• Code reusability
• Easy maintenance
• Better organization
Example: import math
print([Link](25))
8) What is Package in Python? (2 Marks)
A package is a collection of Python modules stored in a folder.
Advantages:
• Organizes modules
• Avoids naming conflicts
• Improves project structure
9) What is NumPy in Python? (2 Marks)
NumPy is a Python library used for numerical and scientific calculations.
Features:
• Supports arrays
• Fast calculations
• Used in data science
10) What is Pandas in Python? (2 Marks)
Pandas is a Python library used for data analysis and manipulation.
Features:
• Works with tables and datasets
• Provides DataFrame structure
• Used in data analytics
11) What is Matplotlib in Python? (2 Marks)
Matplotlib is a Python library used for data visualization and graph plotting.
Features:
• Creates charts and graphs
• Supports line, bar, and pie charts
• Used in data visualization
12) What is Dictionary in Python? (2 Marks)
A dictionary is a collection of key-value pairs.
Features:
• Mutable
• Stores data using keys
• Fast retrieval of values
Example: student = {"name":"Anan","age":20}