T W I S
E
L
G
E
A N
R N I
PYTHON
I
T W I S
E
(BCC-302)
Unit-I : Introduction to Python
L
G
E
Complete
A Notes
I N
R N
PYTHON (BCC 302)
Syllabus
T W I S
I
E
Introduction to Python: Python variables, Python basic
Operators, Understanding python blocks. Python Data Types,
Declaring and using Numeric data types: int, float etc.
G
E
A N
R N I
PYTHON (BCC 302)
Introduction to Python
What is
WPython?
T I S
I
Python is a high-level, general-purpose, interpreted programming language known for its simple,
E
readable syntax.
Created by Guido van Rossum and released in 1991.
Follows object-oriented, functional, and procedural paradigms.
Why Python?
G
E
Easy to learn and write.
A N
Large standard library. R N I
Supports GUI programming.
Highly portable across platforms.
Used in web development, AI, ML, data analysis, scripting, automation, and scientific computing
PYTHON (BCC 302)
Python vs Other Languages
T W I S
I
E
Feature Python
Typing Dynamic
Compilation Interpreted
Syntax Easy, Readable
L
G
E
A N
Memory Management N I (garbage collection)
R Automatic
PYTHON (BCC 302)
Python Installation and Execution
T W I S
I
Installation:
E
Download Python from [Link].
During installation, add Python to PATH for easy terminal usage.
Running Python:
L
G
E
A N
Using IDLE (Python’s inbuilt IDE). R N I
Using terminal/command prompt: python [Link]
PYTHON (BCC 302)
Python Syntax and Structure
W I
T Comments
I S
Used for code documentation.
E
Single-line: # This is a comment
Multi-line: Using multiple # or docstrings (""" Comment """).
Indentation
Python uses indentation to define code blocks instead of braces {}.
Consistent indentation is crucial; typically 4 spaces.
Example
L
G
if True:
E
A N
R
print("Indentation example") N I
Keywords
Reserved words in Python: if, else, elif, while, for, break, continue, def, class, import, return, True, False, None etc.
PYTHON (BCC 302)
Python Variables
Definition:
Variables are names that refer T W I locations where data is stored.
I
to memory S
E
Characteristics:
Do not require explicit declaration of type.
Variable names are case-sensitive.
Rules for Naming Variables:
Can contain letters, digits, and underscores.
L
G
Cannot start with a digit. E
A N
R N I
Cannot use reserved keywords.
examples:
x = 10
name = "AKTU"
pi = 3.14
PYTHON (BCC 302)
Python Basic Operators
These are special symbols in Python used to perform arithmetic or logical operations.
T W
An operand is the value on which an operator acts toI complete
S the operation.
ITypes of Operators:
E
a) Arithmetic Operators: Arithmetic operators are symbols used to perform basic math like +, -. *, /, etc
Example:
a = 10
b=3
print(a + b) # 13
print(a % b) # 1
L
G
E
A compare two
b) Relational Operators: Relational operators I N
values and return True or False.
R N
==, !=, >, <, >=, <=
Example:
x = 5
print(x > 3) # True
PYTHON (BCC 302)
Python Basic Operators
c) Logical Operators: Logical operators combine conditions and return True or False.
and, or, not T W I S
I
E
Example:
a = True
b = False
print(a and b) # False
d) Assignment Operators: Assignment operators are used to assign or update values in variables.
G
=, +=, -=, *=, /=, etc.
E
A N
Example: R N I
x=5
x += 3 # x = 8
PYTHON (BCC 302)
Python Basic Operators
e) Membership Operators: To find whether a value or variable is present in a sequence.
in, not in WT I S
I
Example:
E
l = [1, 2, 3]
print(2 in l) # True
f) Identity Operators: Identity operators check whether two variables refer to the same object in
memory.
is, is not
L
G
E
A N
Example:
R N I
a = 5
b = 5
print(a is b) # True
PYTHON (BCC 302)
Understanding Python Blocks
T W I
I Definition: S
A block is a group of statements executed together.
E
Block Identification:
Python uses indentation to define blocks instead of {}.
Indentation should be consistent (typically 4 spaces).
Example:
L
G
if True: E
print("Block starts here") A N
R N I
print("Block continues")
print("Outside the block")
PYTHON (BCC 302)
Other Data Types
Python data types classify data items.
T W I
S operations can be done with it.
I can store and what
They define what kind of value a variable
E
L
G
E
A N
R N I
PYTHON (BCC 302)
Other Data Types
1) Numeric Data Types:
W Iusing these data types:
T numbers
In Python, you can work with different kinds of
I S
int (Integer): Used for whole numbers, positive or negative, and they can be very long.
E
float (Floating-Point): Used for numbers with a decimal point. Be aware that they are not perfectly
precise for all values.
complex: Used for advanced mathematics involving imaginary numbers, written with a j for the
imaginary part (like 1+2j).
Example:
G
age = 25 E
A N
height = 5.9
R N I
impedance = 3 + 4j
print("type(age)") <class 'int'>
print("type(height)") <class 'float'>
print("type(impedance)") <class 'complex'>
PYTHON (BCC 302)
Other Data Types
2) LIST T W I S
I
Purpose: An ordered collection to store multiple items.
E
Contents: Can hold elements of similar or different data types.
Syntax: Items are separated by commas and enclosed in square brackets [ ].
Example:
# A list with different data types
my_list = [1, "hello", 3.14, True]
L
G
E
A N
print(my_list) # Output: [1, 'hello', 3.14, True] R N I
print(type(my_list)) # Output: <class 'list'>
PYTHON (BCC 302)
Other Data Types
3) TUPLE T W I S
Ordered: Items have a defined order. I
E
Immutable: Cannot be altered after creation (no adding, removing, or changing elements).
Syntax: Items are stored within parentheses ( ), separated by commas.
Example:
# Creating a tuple
coordinates = (10, 20)
L
G
person = ("Alice", 30, "Engineer") E
A N
R N I
print(coordinates) # Output: (10, 20)
print(type(coordinates)) # Output: <class 'tuple'>
PYTHON (BCC 302)
Other Data Types
4) DICTIONARY
Structure: Stores data in key/value pairs. T W I
I S
Key Property: Keys must be unique and immutable (e.g., strings, numbers).
E
Ordered: Maintains the insertion order (as of Python 3.7+).
Syntax: Defined with curly braces { }.
Example:
student = {
"name": "Alice", "age": 22, "major": "Computer Science", "grades": [85, 92, 78]
}
L
G
E
A N
print(student)
R N I
# Output: {'name': 'Alice', 'age': 22, 'major': 'Computer Science', 'grades': [85, 92, 78]}
print(type(student)) # Output: <class 'dict'>
PYTHON (BCC 302)
Other Data Types
5) SETS
T W I S
Unordered: Items have no defined order.I
Unique: Duplicate values are automatically removed.
E
Mutable: You can add and remove items, but individual elements must be immutable.
Syntax: Created with curly braces { } or the set() function.
Example:
# Creating a set
fruits = {"apple", "banana", "orange", "apple", "mango"}
G
print(fruits)
E
A I N
R N
# Output: {'orange', 'banana', 'mango', 'apple'} (order may vary)
print(type(fruits)) # Output: <class 'set'>
PYTHON (BCC 302)
Difference between Global and local variable
Features T W I S
Local Variable Global Variable
I
E
Accessible only within the Accessible throughout the
Scope & Accessibility
function where declared entire program
Created when function is
Created when program starts,
Scope & Accessibility called, destroyed when
destroyed when program ends
function exits
Stored in data segment of
Memory Location Stored in stack memory
memory
L
G
E
A
Cannot be directly
I N
Data Sharing R N
accessed by other
Can be accessed and modified
by any function
functions
No special keyword needed Requires global keyword to
Modification
for declaration modify inside functions
PYTHON (BCC 302)
T W I S
I
E
L
G
E
A N
R N I