SBC3TT301 · Python Programming · Unit I
PYTHON PROGRAMMING · SBC 3TT301
Unit I
Introduction to Python & Operators
Basics · Syntax · Data Types · Variables · Comments · Operators
Page 1 of 9
SBC3TT301 · Python Programming · Unit I
Contents
Unit I — Introduction to Python & Operators
1.1 Introduction to Python — What Python is, and why it's widely used
1.2 Installing Python — Setting up Python and confirming it works
1.3 Basic Syntax — Core rules that shape how Python code is written
1.4 Data Types & Variables — How values are stored and labelled with names
1.5 Immutable Variables & Numeric Types — Why some values change in place and others don't
1.6 Comments & Command Line Arguments — Annotating code and reading terminal input
1.7 Operators — The symbols Python uses to act on values
Page 2 of 9
SBC3TT301 · Python Programming · Unit I
1.1 Introduction to Python
What Python is, and why it's widely used.
Python is a high-level, interpreted, general-purpose programming language known for its readable syntax
and broad standard library. It supports multiple paradigms, including procedural, object-oriented, and
functional programming.
Key Characteristics
– Simple & Readable — code reads close to plain English, reducing development time.
– Interpreted — code runs line-by-line via an interpreter; no separate compile step.
– Cross-Platform — the same Python code runs on Windows, macOS, and Linux.
– Batteries Included — comes with built-in modules for files, math, networking, and more.
– Versatile — widely used in web development, data science, automation, and AI.
1.2 Installing Python
Setting up Python on your machine and confirming it works.
Python can be installed from the official source or via package managers. Once installed, two tools are
commonly used to run code:
Step Action Notes
1 Download installer From [Link] for your OS
2 Run setup Tick ‘Add Python to PATH’ on Windows
3 Verify install Run python --version in terminal
4 Use IDLE / IDE IDLE ships with Python; VS Code is popular
Quick Check
$ python --version
Python 3.12.x
$ python
>>> print("Hello, Python")
Hello, Python
1.3 Basic Syntax
The core rules that shape how Python code is written.
– Indentation — blocks are defined by consistent spacing, not braces.
Page 3 of 9
SBC3TT301 · Python Programming · Unit I
– Statement End — no semicolon required; one statement per line.
– Case Sensitivity — identifiers are case-sensitive (Age ≠ age).
– Keywords — module names — keywords like if, def, class are reserved.
if 5 > 2:
print("Five is greater than two")
else:
print("Condition false")
1.4 Data Types & Variables
How values are stored and labelled with names in Python.
A variable is a name bound to a value. Python is dynamically typed — you don't declare a type; it's inferred
from the assigned value.
Data Types at a Glance
Assignment
x = 10 # simple assignment
a=b=c=0 # multiple assignment
x, y = 1, 2 # tuple unpacking
1.5 Immutable Variables & Numeric Types
Why some values can change in place and others can't.
Page 4 of 9
SBC3TT301 · Python Programming · Unit I
An immutable object's value cannot change after creation; any ‘modification’ actually creates a new
object. int, float, str, and tuple are immutable. list and dict are mutable.
Numeric Type Description Example
int Integers, unlimited precision 10, -3, 1000000
float Floating-point numbers 3.14, -0.5
complex Complex numbers (a + bj) 2 + 3j
x=5
y=x # y now also refers to 5
x=6 # a NEW int object is created
print(y) # 5 -- y is unaffected
1.6 Comments & Command Line Arguments
Annotating code and reading input passed in from the terminal.
Comments
Notes in the code that the interpreter ignores; used to explain logic for readers.
# This is a single-line comment
"""
This is a multi-line comment
(technically a string literal)
"""
Command Line Arguments
Also known as "Command Line Arguments," this concept is about passing data to a Python program from
the outside. In other words, instead of running the program through the idle, it runs directly on the OS
terminal.
To capture these outside instructions, Python uses a built-in module called sys. Specifically, it uses a list
called [Link] (which stands for "System Argument Vector").
import sys
print("Script name:", [Link][0])
print("Arguments:", [Link][1:])
# Instead of just clicking a "Run" button in your IDE, you open your terminal and type:
# Run as: python [Link] hello world
Page 5 of 9
SBC3TT301 · Python Programming · Unit I
# Output: Arguments: ['hello', 'world']
1.7 Operators
The symbols Python uses to act on values and build expressions.
Operators act on values (operands) to produce a result. Python groups them into six categories.
Arithmetic Operators
Perform mathematical calculations.
Operator Description Example
+ Addition 5+3→8
- Subtraction 5-3→2
* Multiplication 5 * 3 → 15
/ Division (float) 5 / 2 → 2.5
// Floor division 5 // 2 → 2
% Modulus (remainder) 5%2→1
** Exponentiation 5 ** 2 → 25
Example
a, b = 10, 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.333...
print(a // b) # 3
print(a % b) # 1
print(a ** b) # 1000
Comparison Operators
Compare two values; always return a Boolean.
Operator Description Example
== Equal to 5 == 5 → True
!= Not equal to 5 != 3 → True
Page 6 of 9
SBC3TT301 · Python Programming · Unit I
Operator Description Example
> Greater than 5 > 3 → True
< Less than 5 < 3 → False
>= Greater than or equal to 5 >= 5 → True
<= Less than or equal to 5 <= 3 → False
Example
a, b = 10, 3
print(a == b) # False
print(a != b) # True
print(a > b) # True
print(a < b) # False
print(a >= b) # True
print(a <= b) # False
Assignment Operators
Assign a value, optionally combined with an operation.
Operator Description Example
= Assign value x=5
+= Add and assign x += 3
-= Subtract and assign x -= 3
*= Multiply and assign x *= 3
/= Divide and assign x /= 3
//= Floor divide and assign x //= 3
%= Modulus and assign x %= 3
**= Exponent and assign x **= 3
Example
x=5
x += 3 #x=8
x -= 2 #x=6
x *= 4 # x = 24
x //= 3 #x=8
Page 7 of 9
SBC3TT301 · Python Programming · Unit I
Logical Operators
Combine Boolean expressions.
Operator Description Example
and True if both are true True and False → False
or True if at least one is true True or False → True
not Reverses the result not True → False
Example
p, q = True, False
print(p and q) # False
print(p or q) # True
print(not p) # False
Membership Operators
Test whether a value exists in a sequence.
Operator Description Example
in True if found in sequence 3 in [1,2,3] → True
not in True if not found in sequence 5 not in [1,2,3] → True
Example
fruits = ["apple", "banana", "cherry"]
print("banana" in fruits) # True
print("mango" not in fruits) # True
Identity Operators
Check whether two variables reference the same object.
Operator Description Example
is True if same object x is y
is not True if not the same object x is not y
Example
Page 8 of 9
SBC3TT301 · Python Programming · Unit I
list1 = [1, 2, 3]
list2 = [1, 2, 3]
list3 = list1
print(list1 is list2) # False - different objects
print(list1 is list3) # True - same object
print(list1 is not list2) # True
Unit I — Quick Recap
– Python Basics — dynamic typing, indentation-based syntax, interpreted execution.
– Core Data Types — int, float, str, bool, list, tuple, dict.
– Mutability — immutable types create new objects on change; mutable types update in place.
– Six Operator Families — arithmetic, comparison, assignment, logical, membership, identity.
Page 9 of 9