Part 2: Objects, Variables, and Datatypes


5. Python Objects

Lecture Video
Code Snippet
print(10)
print(type(10))

print("Python")
print(type("python"))

print(10+20)
print("Hello"+"world")

#Python Interpreter caches integers from -5 to 256 at the startup

6. Variables in Python

Lecture Video
Code Snippet
name = "Sachin"
rollno = 101
score1 = 60
score2 = 80
score3 = 70

print("Name:", name)
total = score1+score2+score3
print("Total score:", total)

#Calculator
a = 20
b = 4
print("Simple Calculator")
print("Addition:", a+b)
print("Subtraction:", a-b)
print("Multiplication:", a*b)
print("Division:", a/b)

#Reassignment
print("Reassignment")
a = 10
print(a)
a = 20
print(a)

#Datatype of variable
print("Datatype of variable")
a = 5
print(a, type(a))
a = "Hello"
print(a, type(a))

#Ways of assigning values to variables
print("Ways of assigning values to variables")
a, b, c = 10, "Hello", 6.5
print(a, b, c)
a = b = c = 10
print(a,b,c)

7. Naming Variables

Lecture Video
Code Snippet
import keyword
print(keyword.kwlist)

_abc = 10
print(_abc)

name = "bob"
age = 25

student_name = "bob"
roll_no = 101
country_of_residence = "India"

name = "Sachin"
Name = "Sourav"
NAME = "Rahul"
print(name, Name, NAME)

8. Scalar datatypes in Python

Lecture Video
Code Snippet
#Integers
age = 25
batch_size = 100
no_of_items = 30
print(age, type(age))

a = 2345272788282929
b = 76547657465476547564
print(a+b)

#floats
price = 10.99
gpa = 3.8
temperature = 22.7
print(price, type(price))

#Complex numbers
cnum = 3+4j
print(cnum, type(cnum))

#boolean datatype
email_verified = False
if email_verified:
    print("You can access the website")
else:
    print("Please complete email verification to get access")

is_item_available = True
print(is_item_available, type(is_item_available))

#None datatype
email = None
print(email, type(email))

9. Immutability of scalar objects

Lecture Video
Code Snippet
a = 5
b = a
print(a,b)
print(id(a), id(b))

a = 10
print(a,b)
print(id(a), id(b))