SlideShare a Scribd company logo
Python
Scope and
Application
02
Python
real-world
applications
and their scope
Installation
03
Understanding
the process of
installation of
python
Python Basics
04
Understanding
the basics of
python
Python:
Introduction
and Different
Versions
01
An introduction to
python programming
language, its versions,
and their comparative
study
Agenda
Python:
Introduction and
Different Versions
of Python
Python is a programming
language that was created by
Guido van Rossum
It was first released in 1991
Features of python
programming language
Easy to learn, easy to code
Object oriented elements
Platform independent
Interpreted
Python: Introduction
There are two major versions of python, python 2.0, and python 3.0.
• Python 2.0 was released in the year 2000.
• Python 3.0 was released in the year 2008.
• Python 3.0 is the latest major release of python, and we will be using this version to write codes.
Python: Versions
IMPORTANT!
Python 3.0 is NOT completely backward-compatible with python 2.0.
Python: Versions Comparison
Basis of comparison Python 3 Python 2
Release Date 2008 2000
Function print print ("hello") print "hello*
Division of Integers
Whenever two integers are divided, you get a float
value
When two integers are divided, you always provide
integer value.
Unicode In Python 3, default storing of strings is Unicode.
To store Unicode string value, you require to define
them with "u".
Syntax The syntax is simpler and easily understandable.
The syntax of Python 2 was comparatively difficult to
understand.
Rules of ordering
Comparisons
In this version. Rules of ordering comparisons have
been simplified.
Rules of ordering comparison are very complex.
Iteration
The new Range() function introduced to perform
iterations.
In Python 2, the xrange() is used for iterations.
Python is used for:
Machine Learning
Data Science
Web Application
Development
Game Development
Python: Applications
Library Use
pymongo Database connectivity
TensorFlow Performing high-level computation
Matplotlib Plotting numerical data
Pandas Data analysis
PyGame Develop games
• Machine learning is the study of computer algorithms that can improve automatically through
experience and by the use of data. It is a part of artificial intelligence.
• Machine Learning algorithms are fed with large amount of data and then these algorithms predict
outcomes of the given problems using python.
Machine Learning Algorithms in Python:
• Linear regression
• Decision tree
• Logistic regression
• Support Vector Machines (SVM)
• Naive Bayes
Python: Versions
Python for machine learning
• Data science is an interdisciplinary field that uses scientific methods, processes, algorithms, and systems
to extract knowledge and insights from noisy, structured, and unstructured data, and apply knowledge and
actionable insights from data across a broad range of application domains.
• Python is widely used for performing different data science operations on datasets like create, read,
update, delete (CRUD), visualize, etc.
Python: Versions
Python for data science
keras
sklearn
numpy
matplotlib
tensorflow
• Python offers many frameworks from which to choose from, including Bottle.py, Flask, CherryPy, Pyramid, Django and
web2py.
• These frameworks have been used to power some of the world's most popular sites such as Spotify, Mozilla, Reddit,
etc.
Python: Versions
Python for web application
• Python provides a built-in library called pygame, which used to develop the game.
• Pygame is a cross-platform library that is used to design video and browser games.
• We can use the pygame library to make games with attractive graphics and suitable animation.
Python: Versions
Python for game development
Python:
Installation
To download python, visit the following link:
Python: Installation
https://www.python.org/downloads/
Run the installer.
01
Make sure to select
“Add Python to
PATH” option on
bottom left corner
of the installer
window.
02
In case this option
was not selected, we
have to add path to
python installation in
PATH variable
manually.
03
Keep the default
values for the
remaining steps.
04
Python: Installation
• After installation is complete, to check the version of python installed on your system, use
“python --version” command in cmd window.
Python: Installation
“python --version” command in cmd window
• To write and execute python code in cmd, use “py”
Python: Installation
• An integrated development environment (IDE) is software for building applications that combines common
developer tools into a single graphical user interface (GUI).
• There are different types of IDEs like PyCharm, Visual Studio Code, etc.
• These IDEs are popularly used to develop complex applications in different frameworks.
• IDEs provide flexibility to use different programming languages like python, JavaScript, C++, etc.
Python: Integrated Development Environment (IDE)
To download PyCharm, visit the following link and click on download button:
Python: Pycharm IDE Installation
https://www.jetbrains.com/pycharm/
Python: Pycharm IDE Installation
Now, download community version installer by clicking download button below community.
Python: Pycharm IDE Installation
Run the PyCharm
installer.
01
Click next and you
can change the
destination folder
by clicking the
browse button.
02
Click on “create
desktop icon” button
and start installation
by clicking the install
button.
03
After installation,
click the finish
button.
04
• Visual Studio Code, also commonly referred as VS Code, is a source-code editor made by Microsoft
for Windows, Linux, and macOS.
• Features include support for debugging, syntax highlighting, intelligent code completion, snippets,
code refactoring, and embedded Git.
Python: Visual Studio Code
To download vs code, visit the following link and click on download button:
Python: Visual Studio Code Installation
https://code.visualstudio.com/download
Python: Visual Studio Code Installation
Run VScode
installer.
01
You can change
destination folder
for installation of
files.
02
Click “create desktop
icon” button.
03
Also, make sure
that you enable
“add to path” and
“Register code as
an editor for
supported files
type” button.
04
Then click on
next and install
button.
05
Create a file in vs code
with .py extension
Go to extensions > search
for “Python v2022.6.0” by
Microsoft.
Click install
Python: Visual Studio Code Installation
Hands-on
Python: Basics
• Unlike other programming languages such as java, there is no need to write too much boilerplate
code in python.
• To print a string/message on the console window, print function is used.
Our first python program: hello world!
Python: Basics
• Write the code given in the image in a file.
• Save it by the name “demo.py”
• Files containing python source code are saved with .py extension
Python: Basics
Our first python program: hello world!
• To execute the code present in a file, use “py file-name.py” command in cmd window.
Python: Basics
Our first python program: hello world!
• Take a number input from user and then display that number in output.
User input in python
Python: Basics
• There is no keyword to declare variables in python.
• Variables are created by writing the name and assigning the values.
• A single variable can be used to store values of different types.
Variable
Python: Basics
• Take age input in years from user and then calculate this age in days by multiplying age by 365.
• Find error in this code below.
Python program for calculating age in days
Python: Basics
Hands-on
• Some of the data-types present in python are:
▪ str
▪ int, float, complex
▪ bytes,
▪ bool
▪ list, set, tuple, range, dictionary
Variables and data types
Python: Basics
Numeric Dictionary Boolean Set
Sequence
Type
Integer Float
Complex
Number
Strings Tuple
List
Python – Data Types
• To check the type of a variable in python, type() is used.
Data types
Python: Basics
Code Output
Important!
String in python can be written using “ ” as well as ‘ ‘
Line by line execution and errors in python
Python: Basics
• In python, execution happens line by line meaning that the execution of the python program will
happen from top to down.
• Whatever line you have written at the top will be executed first and the rest of the lines will be
executed sequentially.
• If you do not follow the python language instructions or if you make a mistake while writing the
code, then python will give you an error message in console.
Line by line execution and errors in python
Python: Basics
• An example to the errors and sequential programming is displayed below.
• In this example “variable1” at line number 3, a variable is declared; it is access at line number 2,
where an error is shown.
• The error has occurred only at line number 2, but not in line 3 and 4, which get executed after this
error. Execution was stopped at line number 2.
Hands-on
• Operators are used to perform operations on data, which is either received from user or manually
entered.
• The operators are divided into following groups:
▪ Arithmetic operators
▪ Assignment operators
▪ Comparison operators
▪ Logical operators
▪ Identity operators
Membership operators most commonly used operators that we will discuss here are Arithmetic,
Comparison, Assignment and Logical operators.
Operators
Python: Basics
Arithmetic operators
Python: Basics
Operator Name Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus x % y
** Exponentiation x ** y
// Floor division x // y
Arithmetic operators' hands on
Python: Basics
Assignment operators
Python: Basics
Operator Example Example same as below
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
Assignment operators' hands on
Python: Basics
Comparison operators
Python: Basics
Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>=
Greater than or
equal to
x >= y
<=
Less than or
equal to
x <= y
Comparison operators’ hands on
Python: Basics
Logical operators
Python: Basics
Operator Description Example
and
Returns True if both
statements are true
x < 5 and x < 10
or
Returns True if one of the
statements is true
x < 5 or x < 4
not
Reverse the result, returns
False if the result is true
not(x < 5 and x < 10)
Logical operators' hands on
Python: Basics
Hands-on
Python is a programming language that was created by Guido van Rossum.
It was first released in 1991.
It is easy to learn and easy to code language.
Unlike other programming languages such as java, there is no need to write too much boilerplate
code in python.
Use of famous code editors like Visual Studio code, PyCharm etc.
Different operators in python include Arithmetic, Comparison, Assignment and Logical operators.
Summary
Python: MCQs
Q1. Main difference between python 2 and python 3
a) Print is a statement in python 2 and a function in python 3.
b) Python 2 is syntactically difficult than python 3.
c) Python 3 is not completely backward-compatible with python 2.
d) Python 3 has more usage than python 2.
e) None of the above
Q2. Predict output of code given below
a = 10
a = 20
a = 30
a = 40
print(a)
a) 10
b) 20
c) 30
d) 40
e) None of the above
Python: MCQs
Q3. Predict output of code given below
a = 30
b = 40
print(a */ b)
a) 1200
b) 0.75
c) Error message “invalid syntax”
d) 40
e) None of the above
Q4. Predict output of code given below
a = True
b = False
print((a and b) or a)
a) True
b) False
c) Error message “invalid syntax”
d) None of the above
Python: MCQs
Q5. Predict output of code given below
a = 30
b = 40
c = 60
d = 100
print( (a <= 30 and b <=60) and (c == 60 or d <= 200))
a) True
b) False
c) Error message “invalid syntax”
d) None of the above
Q6. Predict output of code given below
a = 20
b = 20
c = a*b
print()
a) 400
b) 20
c) Error message “print function empty”
d) No output
e) None of the above
Python: MCQs
Q7. Predict output of code given below
a = 30
b = 40
c = 60
d = 100
print( (a <= 30 and b <=60) or (c == 60 and d <= 200))
a) True
b) False
c) Error message “invalid syntax”
d) None of the above
Q8. Predict output of code given below
a = 50
b = 60
c = 2000
d = 100
print( (a <= 30 or b <=60) or (c == 60 or d <= 200) )
a) True
b) False
c) Error message “invalid syntax”
d) None of the above
Python: MCQs
Q9. Predict output of code given below
a = 2
a **= 3
b = 20
b /= 10
print(a**b)
a) 20
b) 64.0
c) Error message “invalid syntax”
d) None of the above
Q10. Predict output of code given below
a = 50
b = 100
c = 200
print((a < 1000 and b > 50) and c > 10)
a) True
b) False
c) Error message “invalid syntax”
d) None of the above
Thank You!
Copyright © HeroX Private Limited, 2022. All rights reserved.

More Related Content

Similar to Introduction to Python.pdf (20)

PPT
Spsl iv unit final
Sasidhar Kothuru
 
PDF
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPTX
4_Introduction to Python Programming.pptx
Gnanesh12
 
PPTX
Python PPT.pptx
JosephMuez2
 
PDF
python-handbook.pdf
RaviKumar76265
 
PDF
Python basics_ part1
Elaf A.Saeed
 
PPTX
UNIT 1 PYTHON introduction and basic level
vasankarponnapalli2
 
PPTX
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
PPTX
Python basics
ssuser4e32df
 
PDF
Tutorial on-python-programming
Chetan Giridhar
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
05 python.pdf
SugumarSarDurai
 
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
PDF
Introduction-to-Python-print-datatype.pdf
AhmedSalama337512
 
PPTX
Learn about Python power point presentation
omsumukh85
 
PPTX
Python Programming-1.pptx of python by computer
sharanyarashmir5
 
PPTX
Python_ppt for basics of python in details
Mukul Kirti Verma
 
PDF
An overview on python commands for solving the problems
Ravikiran708913
 
Spsl iv unit final
Sasidhar Kothuru
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
4_Introduction to Python Programming.pptx
Gnanesh12
 
Python PPT.pptx
JosephMuez2
 
python-handbook.pdf
RaviKumar76265
 
Python basics_ part1
Elaf A.Saeed
 
UNIT 1 PYTHON introduction and basic level
vasankarponnapalli2
 
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
Python basics
ssuser4e32df
 
Tutorial on-python-programming
Chetan Giridhar
 
Python basic programing language for automation
DanialHabibi2
 
05 python.pdf
SugumarSarDurai
 
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Introduction-to-Python-print-datatype.pdf
AhmedSalama337512
 
Learn about Python power point presentation
omsumukh85
 
Python Programming-1.pptx of python by computer
sharanyarashmir5
 
Python_ppt for basics of python in details
Mukul Kirti Verma
 
An overview on python commands for solving the problems
Ravikiran708913
 

Recently uploaded (20)

PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Ad

Introduction to Python.pdf

  • 2. Scope and Application 02 Python real-world applications and their scope Installation 03 Understanding the process of installation of python Python Basics 04 Understanding the basics of python Python: Introduction and Different Versions 01 An introduction to python programming language, its versions, and their comparative study Agenda
  • 4. Python is a programming language that was created by Guido van Rossum It was first released in 1991 Features of python programming language Easy to learn, easy to code Object oriented elements Platform independent Interpreted Python: Introduction
  • 5. There are two major versions of python, python 2.0, and python 3.0. • Python 2.0 was released in the year 2000. • Python 3.0 was released in the year 2008. • Python 3.0 is the latest major release of python, and we will be using this version to write codes. Python: Versions IMPORTANT! Python 3.0 is NOT completely backward-compatible with python 2.0.
  • 6. Python: Versions Comparison Basis of comparison Python 3 Python 2 Release Date 2008 2000 Function print print ("hello") print "hello* Division of Integers Whenever two integers are divided, you get a float value When two integers are divided, you always provide integer value. Unicode In Python 3, default storing of strings is Unicode. To store Unicode string value, you require to define them with "u". Syntax The syntax is simpler and easily understandable. The syntax of Python 2 was comparatively difficult to understand. Rules of ordering Comparisons In this version. Rules of ordering comparisons have been simplified. Rules of ordering comparison are very complex. Iteration The new Range() function introduced to perform iterations. In Python 2, the xrange() is used for iterations.
  • 7. Python is used for: Machine Learning Data Science Web Application Development Game Development Python: Applications Library Use pymongo Database connectivity TensorFlow Performing high-level computation Matplotlib Plotting numerical data Pandas Data analysis PyGame Develop games
  • 8. • Machine learning is the study of computer algorithms that can improve automatically through experience and by the use of data. It is a part of artificial intelligence. • Machine Learning algorithms are fed with large amount of data and then these algorithms predict outcomes of the given problems using python. Machine Learning Algorithms in Python: • Linear regression • Decision tree • Logistic regression • Support Vector Machines (SVM) • Naive Bayes Python: Versions Python for machine learning
  • 9. • Data science is an interdisciplinary field that uses scientific methods, processes, algorithms, and systems to extract knowledge and insights from noisy, structured, and unstructured data, and apply knowledge and actionable insights from data across a broad range of application domains. • Python is widely used for performing different data science operations on datasets like create, read, update, delete (CRUD), visualize, etc. Python: Versions Python for data science keras sklearn numpy matplotlib tensorflow
  • 10. • Python offers many frameworks from which to choose from, including Bottle.py, Flask, CherryPy, Pyramid, Django and web2py. • These frameworks have been used to power some of the world's most popular sites such as Spotify, Mozilla, Reddit, etc. Python: Versions Python for web application
  • 11. • Python provides a built-in library called pygame, which used to develop the game. • Pygame is a cross-platform library that is used to design video and browser games. • We can use the pygame library to make games with attractive graphics and suitable animation. Python: Versions Python for game development
  • 13. To download python, visit the following link: Python: Installation https://www.python.org/downloads/
  • 14. Run the installer. 01 Make sure to select “Add Python to PATH” option on bottom left corner of the installer window. 02 In case this option was not selected, we have to add path to python installation in PATH variable manually. 03 Keep the default values for the remaining steps. 04 Python: Installation
  • 15. • After installation is complete, to check the version of python installed on your system, use “python --version” command in cmd window. Python: Installation “python --version” command in cmd window
  • 16. • To write and execute python code in cmd, use “py” Python: Installation
  • 17. • An integrated development environment (IDE) is software for building applications that combines common developer tools into a single graphical user interface (GUI). • There are different types of IDEs like PyCharm, Visual Studio Code, etc. • These IDEs are popularly used to develop complex applications in different frameworks. • IDEs provide flexibility to use different programming languages like python, JavaScript, C++, etc. Python: Integrated Development Environment (IDE)
  • 18. To download PyCharm, visit the following link and click on download button: Python: Pycharm IDE Installation https://www.jetbrains.com/pycharm/
  • 19. Python: Pycharm IDE Installation Now, download community version installer by clicking download button below community.
  • 20. Python: Pycharm IDE Installation Run the PyCharm installer. 01 Click next and you can change the destination folder by clicking the browse button. 02 Click on “create desktop icon” button and start installation by clicking the install button. 03 After installation, click the finish button. 04
  • 21. • Visual Studio Code, also commonly referred as VS Code, is a source-code editor made by Microsoft for Windows, Linux, and macOS. • Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Python: Visual Studio Code
  • 22. To download vs code, visit the following link and click on download button: Python: Visual Studio Code Installation https://code.visualstudio.com/download
  • 23. Python: Visual Studio Code Installation Run VScode installer. 01 You can change destination folder for installation of files. 02 Click “create desktop icon” button. 03 Also, make sure that you enable “add to path” and “Register code as an editor for supported files type” button. 04 Then click on next and install button. 05
  • 24. Create a file in vs code with .py extension Go to extensions > search for “Python v2022.6.0” by Microsoft. Click install Python: Visual Studio Code Installation
  • 27. • Unlike other programming languages such as java, there is no need to write too much boilerplate code in python. • To print a string/message on the console window, print function is used. Our first python program: hello world! Python: Basics
  • 28. • Write the code given in the image in a file. • Save it by the name “demo.py” • Files containing python source code are saved with .py extension Python: Basics Our first python program: hello world!
  • 29. • To execute the code present in a file, use “py file-name.py” command in cmd window. Python: Basics Our first python program: hello world!
  • 30. • Take a number input from user and then display that number in output. User input in python Python: Basics
  • 31. • There is no keyword to declare variables in python. • Variables are created by writing the name and assigning the values. • A single variable can be used to store values of different types. Variable Python: Basics
  • 32. • Take age input in years from user and then calculate this age in days by multiplying age by 365. • Find error in this code below. Python program for calculating age in days Python: Basics
  • 34. • Some of the data-types present in python are: ▪ str ▪ int, float, complex ▪ bytes, ▪ bool ▪ list, set, tuple, range, dictionary Variables and data types Python: Basics Numeric Dictionary Boolean Set Sequence Type Integer Float Complex Number Strings Tuple List Python – Data Types
  • 35. • To check the type of a variable in python, type() is used. Data types Python: Basics Code Output Important! String in python can be written using “ ” as well as ‘ ‘
  • 36. Line by line execution and errors in python Python: Basics • In python, execution happens line by line meaning that the execution of the python program will happen from top to down. • Whatever line you have written at the top will be executed first and the rest of the lines will be executed sequentially. • If you do not follow the python language instructions or if you make a mistake while writing the code, then python will give you an error message in console.
  • 37. Line by line execution and errors in python Python: Basics • An example to the errors and sequential programming is displayed below. • In this example “variable1” at line number 3, a variable is declared; it is access at line number 2, where an error is shown. • The error has occurred only at line number 2, but not in line 3 and 4, which get executed after this error. Execution was stopped at line number 2.
  • 39. • Operators are used to perform operations on data, which is either received from user or manually entered. • The operators are divided into following groups: ▪ Arithmetic operators ▪ Assignment operators ▪ Comparison operators ▪ Logical operators ▪ Identity operators Membership operators most commonly used operators that we will discuss here are Arithmetic, Comparison, Assignment and Logical operators. Operators Python: Basics
  • 40. Arithmetic operators Python: Basics Operator Name Example + Addition x + y - Subtraction x - y * Multiplication x * y / Division x / y % Modulus x % y ** Exponentiation x ** y // Floor division x // y
  • 41. Arithmetic operators' hands on Python: Basics
  • 42. Assignment operators Python: Basics Operator Example Example same as below = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 //= x //= 3 x = x // 3 **= x **= 3 x = x ** 3
  • 43. Assignment operators' hands on Python: Basics
  • 44. Comparison operators Python: Basics Operator Name Example == Equal x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 45. Comparison operators’ hands on Python: Basics
  • 46. Logical operators Python: Basics Operator Description Example and Returns True if both statements are true x < 5 and x < 10 or Returns True if one of the statements is true x < 5 or x < 4 not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
  • 47. Logical operators' hands on Python: Basics
  • 49. Python is a programming language that was created by Guido van Rossum. It was first released in 1991. It is easy to learn and easy to code language. Unlike other programming languages such as java, there is no need to write too much boilerplate code in python. Use of famous code editors like Visual Studio code, PyCharm etc. Different operators in python include Arithmetic, Comparison, Assignment and Logical operators. Summary
  • 50. Python: MCQs Q1. Main difference between python 2 and python 3 a) Print is a statement in python 2 and a function in python 3. b) Python 2 is syntactically difficult than python 3. c) Python 3 is not completely backward-compatible with python 2. d) Python 3 has more usage than python 2. e) None of the above Q2. Predict output of code given below a = 10 a = 20 a = 30 a = 40 print(a) a) 10 b) 20 c) 30 d) 40 e) None of the above
  • 51. Python: MCQs Q3. Predict output of code given below a = 30 b = 40 print(a */ b) a) 1200 b) 0.75 c) Error message “invalid syntax” d) 40 e) None of the above Q4. Predict output of code given below a = True b = False print((a and b) or a) a) True b) False c) Error message “invalid syntax” d) None of the above
  • 52. Python: MCQs Q5. Predict output of code given below a = 30 b = 40 c = 60 d = 100 print( (a <= 30 and b <=60) and (c == 60 or d <= 200)) a) True b) False c) Error message “invalid syntax” d) None of the above Q6. Predict output of code given below a = 20 b = 20 c = a*b print() a) 400 b) 20 c) Error message “print function empty” d) No output e) None of the above
  • 53. Python: MCQs Q7. Predict output of code given below a = 30 b = 40 c = 60 d = 100 print( (a <= 30 and b <=60) or (c == 60 and d <= 200)) a) True b) False c) Error message “invalid syntax” d) None of the above Q8. Predict output of code given below a = 50 b = 60 c = 2000 d = 100 print( (a <= 30 or b <=60) or (c == 60 or d <= 200) ) a) True b) False c) Error message “invalid syntax” d) None of the above
  • 54. Python: MCQs Q9. Predict output of code given below a = 2 a **= 3 b = 20 b /= 10 print(a**b) a) 20 b) 64.0 c) Error message “invalid syntax” d) None of the above Q10. Predict output of code given below a = 50 b = 100 c = 200 print((a < 1000 and b > 50) and c > 10) a) True b) False c) Error message “invalid syntax” d) None of the above
  • 55. Thank You! Copyright © HeroX Private Limited, 2022. All rights reserved.