0% found this document useful (0 votes)
4 views4 pages

Python MidSem Study Material

This study material covers the fundamentals of Python programming, including its basics, variables, keywords, identifiers, and data types. It also discusses control flow with conditional and looping statements, as well as functions, including their types and lambda functions. Key exam tips emphasize understanding list methods and the performance differences between tuples and lists.

Uploaded by

wlakeryash
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Python MidSem Study Material

This study material covers the fundamentals of Python programming, including its basics, variables, keywords, identifiers, and data types. It also discusses control flow with conditional and looping statements, as well as functions, including their types and lambda functions. Key exam tips emphasize understanding list methods and the performance differences between tuples and lists.

Uploaded by

wlakeryash
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programming

Mid-Semester Examination Study Material

Unit 1: Fundamentals

1. Python Basics

Python is a high-level, interpreted, general-purpose programming language created


by Guido van Rossum and first released in 1991. It is designed with an emphasis on
code readability.

Key Features

• Interpreted: Code is executed line-by-line, which facilitates easy debugging.


• Interactive: You can interact with the interpreter directly to write your
programs.
• Object-Oriented: Supports the OOP paradigm, encapsulating code within
objects.
• Dynamic Typing: No need to declare the type of a variable when you create
one.

2. Variables, Keywords & Identifiers

Variables: Reserved memory locations to store values.


Example: x = 10

Keywords: Reserved words that have a special meaning to the compiler/interpreter.


You cannot use them as constant or variable names. Examples: False , class ,
finally , is , return , None , continue , for , lambda , try .

Page 1
Identifiers: The name given to entities like class, functions, variables.
Rules: Can be a combination of letters (a-z, A-Z), digits (0-9), or an underscore (_). It
cannot start with a digit.

3. Data Types

Category Type Example Description

int, float, 5, 3.14,


Numbers Holds numeric values.
complex 2+3j

Immutable sequence of
Sequence String "Hello"
characters.

Ordered, mutable collection of


Sequence List [1, 2, 'a']
items.

Sequence Tuple (1, 2, 'a') Ordered, immutable collection.

{"key": Unordered collection of key-value


Mapping Dictionary
"val"} pairs.

Unordered collection of unique


Set Set {1, 2, 3}
items.

Page 2
Unit 2: Control Flow & Functions

1. Control Flow

Conditional Statements

Decision making is required when we want to execute a code only if a certain


condition is satisfied.

if condition:
# block of code
elif condition:
# block of code
else:
# block of code

Looping Statements

• For Loop: Used for iterating over a sequence (list, tuple, string) or other iterable
objects.
• While Loop: Used to iterate over a block of code as long as the test expression
(condition) is true.

2. Functions in Python

A function is a block of organized, reusable code that is used to perform a single,


related action.

Function Arguments

1. Required arguments: Passed in correct positional order.


2. Keyword arguments: Caller identifies arguments by parameter name.
3. Default arguments: Assumes a default value if a value is not provided.
4. Variable-length (*args): Process a function for more arguments than you
specified while defining it.

Page 3
Lambda Functions

These are small anonymous functions defined with the lambda keyword. They can
take any number of arguments but can only have one expression.

# Syntax: lambda arguments : expression


multiply = lambda a, b : a * b
print(multiply(5, 6)) # Output: 30

Exam Tip: Practice the difference between append() and extend() in lists,
and understand why Tuples are faster than Lists (Immutability).

Page 4

You might also like