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
print(10)
print(type(10))

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

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

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))