Python ML Bootcamp Lecture 2
Python ML Bootcamp Lecture 2
Introduction
2
Tuesday, 6 December 2022
“An investment in knowledge pays
the best interest“
- BENJAMIN FRANKLIN
Today’s Agenda
• Version History
• This means that a project which uses Python 2 will not run
on Python 3.
• In Python 3
print(“Hello iNeuron”)
• In Python 2
5/2 2
5/2.02.5
• In Python 3
5/2 2.5
• The way of accepting input has also changed and like this
there are many changes
The Two Versions Of Python
• So to prevent this overhead of programmers , PSF decided to
support Python 2 also.
• Built In Functions
print("Python Rocks")
But we have changed it to empty string(“”) to tell Python not to produce any
newline.
Similarly we can set it to “\t” to generate tab or “\b” to erase the previous
character
Some Examples
1.
print("Hello User",end="\t")
print("Python Rocks")
2.
print("Hello User",end="\b")
print("Python Rocks")
Types Of Errors In Python
• Just like any other programming language , Python also has 2 kinds of
errors:
• Syntax Error
• Runtime Error
Syntax Error
• Syntaxes are RULES OF A LANGUAGE and when we break
these rules , the error which occurs is called
Syntax Error.
• Misspalled keywords.
• Incorrect use of an operator.
• Omitting parentheses in a function call.
Runtime Errors (Exceptions)
• As the name says, Runtime Errors are errors which occur while the program is
running.
• As soon as Python interpreter encounters them it halts the execution of the program
and displays a message about the probable cause of the problem.
Runtime Errors (Exceptions)
• They usually occurs when interpreter counters a operation that is impossible to carry out
and one such operation is dividing a number by 0.
Python has 100s of built in Modules like math , sys , platform etc which prove to be very
useful for a programmer
Functions Defined
In Modules
For example , the module math contains a function called factorial( ) which can calculate and return the
factorial of any number.
But to use a module we must first import it in our code using the syntax :
◦ import <name of the module>
Then we can call any function of this module by prefixing it with the module name
o A word in a programming language which has a fixed meaning and cannot be redefined by the programmer or used as
identifiers
False , True , None ,def, Except False , True and None all the other keywords are
1.
del ,import ,return , and , or ,
in lowercase
not ,if, else , elif , for , while ,
2.
break , continue, is , as , in ,
We don’t have else if in Python , rather it is elif
global , nonlocal ,yield ,
try ,except , finally, raise,
3. There are no switch and do-while statements in Python
lambda ,with ,assert ,class ,
from , pass
Rules For Identifiers
It must compulsorily begin with a underscore ( _ ) or a letter and not with a digit . Although after the
first letter we can have as many digits as we want. So 1a is invalid , while a1 or _a or _1 is a valid
name for an identifier.
Rules For Identifiers
Identifiers are case sensitive , so pi and Pi are two different identifiers.
Rules For Identifiers
• Keywords cannot be used as identifiers