Day 1

Module 1

Syllabus

# 1
print("Hi Arun CS")
# 2
print("Hey Sneha")

Her Question

Implicit Type Conversion

x = 5      # int
y = 2.5    # float
z = x + y  # int + float
print(z)   # 7.5
print(type(z))  # <class 'float'>

Explicit Type Conversion

a = "42"
b = int(a)     # converting string to int
c = float(b)   # converting int to float
d = str(c)     # converting float back to string

print(a, type(a))  # "42" <class 'str'>
print(b, type(b))  # 42   <class 'int'>
print(c, type(c))  # 42.0 <class 'float'>
print(d, type(d))  # "42.0" <class 'str'>

Keywords

Python keywords are reserved words that have special meanings and purposes within the Python language

Datatypes

# 3 
print(type(2))
print(type(2.0))
print(type(""))

Variables

A variable in Python is like a little label you stick onto a piece of data so you can refer to it later
Eg:
Consider , there is a program in which you have to use 13232132131 this number , its like everywhere in the program

something = 13232132131 / 2
anotherthing = something * 13232132131

sure you can copy paste it but checkout this version

number = 13232132131
something = number /2 
anotherthing = something * number  

its like giving it a suitable name , so that you can use it by name rather than remembering its value.

Operators

  1. Arithmetic

Arithmetic Operators

a , b  = 1 , 2 
a + b  # 3 "#" is the single line comment
a - b  # -1  
a * b  # 2 
a / b  # .5 
a % b  #  1 
b ** 2 # 4
a // b # 0

Comparison Operator

a, b = 5, 10

# Equal to
a == b  # False

# Not equal to
a != b  # True

# Greater than
a > b   # False

# Less than
a < b   # True

# Greater than or equal to
a >= b  # False

# Less than or equal to
a <= b  # True

Logical Operators

x, y = True, False

# AND - True if both operands are True
x and y  # False

# OR - True if at least one operand is True
x or y   # True

# NOT - Inverts the Boolean value 0 -> 1 , 1 -> 0
not x    # False
not y    # True

Membership Operators

lst = [1, 2, 3, 4]
name = "Arun"

# IN - True if value is found in sequence
2 in lst       # True
"run" in name  # True
5 in lst       # False

# NOT IN - True if value is not found in sequence
5 not in lst   # True
"y" not in name # True

Identity Operators

m = [1, 2]
n = [1, 2]
p = m

# IS - True if both variables point to same object
m is p    # True

m is n    # False (same values but different objects)

# IS NOT - True if variables point to different objects
m is not n  # True
print(m is n) # False , different objects even if values are sae
print(m == n) # True same value even if different objects

Bitwise Operators

a , b = 1, 2  # 01 , 10

''' Bitwise AND 
  01
& 10 '''
a & b  # 0

#Bitwise OR
# 11 
a | b  # 3

# Bitwise XOR
 
a ^ b  # 3

# Bitwise NOT
# this might be confusing explain later.
~a     # -2

#  Left Shift (<<)

a << 1  # 2

#Right Shift (>>)
a >> 1  # 0

Assignment Operators

x = 10

x += 3  # x = x + 3 → 13
x -= 2  # 11
x *= 2  #  22
x /= 4  # 5.5
x %= 3  #  2.5
x **= 2 #   6.25
x //= 2 #  3.0

Type Casting

int(3.1) # 3 
float(3) # 3.0
str(10) # '10'
a = 5 
type(a)
a = str(a)
type(a)
a = float(a)
type(a)

Pasted image 20250530165358.png

Input , output , processing

# input
a = input("Enter a number")

# output
print(a)
a = input("Enter a number")
if a==5:
	print("HI")
a = int(input("Enter a number"))
if a==5:
	print("HI")