Module I - Day 1

Python Foundation

Nov-Jan 2025 batch, Vikrant Patil

Date: 20 Sep 2025

Click here for All Notes

© Vikrant Patil

print("hello")
hello

Working with jupyter notebook

Another fancy way of programming python is jupyter notebook. once you launch
jupyter from console or from start menu, a browser will be launched.
Create a new notebook. To work with notebook you need to know few key strokes.

  ===========   ====================================
  keys          action                              
  ===========   ====================================
  esc+m         convert the cell to markdown        
  esc+y         convert the cell to code            
  shift+enter   execute the cell                   
  !command      execute system command from jupyter 
  ===========   ====================================

Basic Datatypes

  • integer - integer (+/- 0)
  • float - (real numbers, decimal numbers)
  • str
3 + 5 
8
5 / 2
2.5
5 // 2 # integer division
2
5 ** 3 #this is a comment .. 5 raised to power 3
125
5.5 + 5.6
11.1
5.5 // 2
2.0
5.0 ** 5 
3125.0
64/8
8.0
5 ** 5
3125
2 ** 100
1267650600228229401496703205376
2**64-1 # c will  have this as max integer value for 64 bit integer
18446744073709551615

priotity

1 + 3 *5 # it follows similar priorities as in excel or in mathematics
16
"vikrant"
'vikrant'
'python'
'python'
"programming"
'programming'
'vikrant' + 'patil' # concatenate the added text
'vikrantpatil'
'*'*5 # this repeates the text 5 times
'*****'
'vikrant'*5
'vikrantvikrantvikrantvikrantvikrant'
3 + 5
5 ** 7 # you will see result of last line
78125
42 + 42
84

built in

  • functions provided by python readily for execution
int("45")
# int - name of built in function
# () into these round parenthesis you pass the argument to function
# "45" is the argument here
45
"45" # this is text
'45'
"45" + 5
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[32], line 1
----> 1 "45" + 5

TypeError: can only concatenate str (not "int") to str
"45" + "45" 
'4545'
45 + 45
90
int("45") + int("45") # this will converted the quoted text into int and then add
90
float("45.6")
45.6
"45" # two characters 4 and 5 
'45'
45 # integer we type decimal digits for our covennince , internally it is stored as binary
45
45 + 45
90
int("45")
45
str(42) # convert objects into text
'42'
len("vikrant") # how many chars are there in the text
7
len(45) # what you intend here is to find number of digit... it is not length of number
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[44], line 1
----> 1 len(45) # what you intend here is to find number of digit... it is not length of number

TypeError: object of type 'int' has no len()
len(str(45)) # convert the integer into text first then find length of that text
2
len(  str(45)  ) # the execution order will be... inner most will be executed first
2
len(str(2**100))
31
2**100
1267650600228229401496703205376

collection

  • collection of objects
  • list - ordered collection of objects which can be modified
  • tuple - ordered collection of objects which can not be modified (immutable object)
  • dictionary - named collection of objects

list

[1, 2, 3, 4, 5, 5]
[1, 2, 3, 4, 5, 5]

variables

name = "python" # = is called as assigment operator
name # interpreter will show what this object in name
'python'
x = 42
x
42
z = 1.5
x, y = 5, 6 # you can assign multple variables in single statement
x + y
11
x
5
y
6
x = 10
y = 20
x = 30

problem think about this

x = 20
y = x
x = 30

what will be value of y after execution of all the three statements?

problem Have a look at following python statements.

    x = 10
    y = x
    x = x + 10

What will be value of y after this?

What will be value of x after executing all statements?

    x = 10
    y = x
    y = 25

collection

  • collection of objects
  • list - ordered collection of objects which can be modified
  • tuple - ordered collection of objects which can not be modified (immutable object)
  • dictionary - named collection of objects
  • text - it is ordered collection of chars (text)

list

nums = [1, 1, 3, 6, 2, 4, 5, 4]
nums
[1, 1, 3, 6, 2, 4, 5, 4]
nums[0] # index starts with 0
1
names = ['vikrant', 'tushar', 'abid', 'pallavi', 'jagdish']
names[0] # indexing is done with square bracket
'vikrant'
names[1]
'tushar'
names[-1] # it will give last item
'jagdish'
names[-2] # it will give second last item
'pallavi'
names[56]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[76], line 1
----> 1 names[56]

IndexError: list index out of range
 names[0]
'vikrant'
names[-3]
'abid'
names[-5] # better access first item with names[0]
'vikrant'
len(names) # len can be used to find length of collection
5
len("vikrant")
7
len(names[0]) # lengh of the first item from names
7
name
'python'
name[0]
'p'

tuple

point = (3, 4, 8)
point
(3, 4, 8)
point[0]
3
len(point)
3
names # it is list
['vikrant', 'tushar', 'abid', 'pallavi', 'jagdish']
names[0] = "VIKRANT"
names
['VIKRANT', 'tushar', 'abid', 'pallavi', 'jagdish']
names[-1] = "JAGDISH"
names
['VIKRANT', 'tushar', 'abid', 'pallavi', 'JAGDISH']
point
(3, 4, 8)
point[0] = 0 # tuple is immutable object
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[100], line 1
----> 1 point[0] = 0 # tuple is immutable object

TypeError: 'tuple' object does not support item assignment
name
'python'
name[0]
'p'
name[0] = "P"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[103], line 1
----> 1 name[0] = "P"

TypeError: 'str' object does not support item assignment
x = 3, 4, 5, 5  # this is also a tuple
x
(3, 4, 5, 5)
x, y = 5, 6
5, 6 # this is also tuple
(5, 6)
(5, 6)
(5, 6)
t = (2, 3, 4, 6)
t = (1, 2, 3, 4) # this not modifying , but creating new one

indexing is always done with square bracket

len(name) # round parenthesis after any name means call that object 
6
t
(1, 2, 3, 4)
t[0] 
1
t[0] = -1
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[118], line 1
----> 1 t[0] = -1

TypeError: 'tuple' object does not support item assignment

dictionary

person = ["vikrant", "prabhakar", "patil"]
person[0]
'vikrant'
person[1]
'prabhakar'
person[2]
'patil'
p = {'firstname' : "vikrant", "middlename": "prabhakar", "lastname": "patil"}
p
{'firstname': 'vikrant', 'middlename': 'prabhakar', 'lastname': 'patil'}
p['firstname']
'vikrant'
p['middlename']
'prabhakar'
p['lastname']
'patil'
point_3d = {'x': 0,   # you can separate every on new line
            'y': 10,  # give comma between every pair
            'z': 20}  # give : betwen every key and value
point_3d['x']
0
point_3d['y']
10
point_3d['z']
20
college = {"physics" : ["phy_std1", "phy_std2"],
 "chemistry" : ["chem_stud1", "chem_stud2"]}
college['physics']
['phy_std1', 'phy_std2']
ps1 = {"name" : "phy_std1",
       "place" : "place1",
       "height" : 5.6}
ps2 = {"name" : "phy_std2",
       "place" : "place2",
       "height" : 5.7}

ch1 = {"name" : "chem_std1",
       "place" : "place3",
       "height" : 6.0}
ch2 = {"name" : "chem_std2",
       "place" : "place4",
       "height" : 6.1}

college_ = {"physics": [ps1, ps2],
            "chemistry": [ch1, ch2]}
college_
{'physics': [{'name': 'phy_std1', 'place': 'place1', 'height': 5.6},
  {'name': 'phy_std2', 'place': 'place2', 'height': 5.7}],
 'chemistry': [{'name': 'chem_std1', 'place': 'place3', 'height': 6.0},
  {'name': 'chem_std2', 'place': 'place4', 'height': 6.1}]}
college_['physics'][0]
{'name': 'phy_std1', 'place': 'place1', 'height': 5.6}
college_['physics'][0]['name']
'phy_std1'
college_['physics'][1]['name']
'phy_std2'
college_['chemistry'][0]['name']
'chem_std1'

brackets

for creating the objects
- for creating a list []
- for creating a tuple ()
- for creating a dictionary {}
- for creating a set {}

for accesing always use square bracket []

list => nums[0]
tuple=> point[0]
dictionary => college['physics']

Homework

problem

  • a cvs file stocks.csv looks like this. How will you represent this data in python using basic and collection data types learnt so far?

      symbol,value,high value,low value,volume
      APPLE,234.5,240.3,233.0,100
      AT&T,221.6,22.5,220.0,200
      IBM,125.7,127.3,123.0,50
      NIKE,100.5,105.0,104.0,1000