SlideShare a Scribd company logo
One Day Workshop
on
Python
Devashish Kumar
Faculty-IT
iNurture
Introduction to Python Part-1
Programming Language
 A programming language is a notation for writing programs.
 A programming language is a computer language designed to
communicate instructions to a machine, particularly a computer.
 Programming languages can be used to create programs, to control the
behaviour of a machine or to express algorithms.
 Various programming languages are such as: c , c++ , R, java, C# , ruby , python
etc.
What is Python ?
Python is a high level programming language which is:
Interpreted
Interactive
Object-Oriented
Dynamic programming language
Open source model
WHY PYTHON ?
Python is nowadays widely used as an programming language. It has :-
 Simple syntax
 One-Line command
 English like commands(easily readable)
 Dynamically Typed
 Easily Indentable
 Intuitive data structures like tuples, sets, dictionaries,strings,lists etc
Applications of Python language
Python language used in:
– Web Development
– Database programming
– Game Development
– Scientific Computing
– Web Framework
– Molecular Biology
WHY 2.7 RELEASE AFTER 3.X ?
• Version 2.X has an awful quantity of useful libraries that haven’t been ported
to 3.X version.
• Current Linux distributions and Macs are still using 2.x as default. Some
are phasing out Python 2 as preinstalled default.
• Python 3 already broadly supports creating GUI applications, with Tkinter
,etc. in the standard library.
• Python 2.7 provides a stable and a supported base platform for production
system that have not yet been ported to Python 3.
 In Python 2.X, range() and xrange() function is used for
iterating and range() function behaves as it is a list.
 In Python 2.X, data type returned is in int,char etc.
 In python 2.X, no TypeError is raised if we try to
compare unorderable type.
 Handling exception: In python 2.X, for handling
exception in the syntax we use comma instead of ‘as’.
 In python 3.X, xrange() function is not used, it gives
name error and range doesnot behave as a list.
 In python 3.x, data type returned is in class.
 In python 3.X, TypeError is raised as warning if we try
to compare unorderable type.
 In python 3.X, for handling exception in the syntax we
use ‘as’ keyword.
 Packages like NumPy and SciPy,
Django,Flask,CherryPy and Pyramid is not
included in python 2.X.
 Integer Division: Python 2.X treats numbers that
you type without any digit after the decimal point
as integers,which can lead to some unexpected
results.
 Raising Exceptions:
 List comprehension loop variables:
 Packages like NumPy and SciPy,
Django,Flask,CherryPy and Pyramid is ported to
python 3.X .
 Python 3.X evaluates “3/2” as 1.5 by default,which
is more intuitive for programmer.
 Raising exceptions:
 List comprehension loop variables:
 Future_module: this module is used to
help in migration.
 .Next() function: Python 2.X supports
.next() function.
 Output:
 Python 2.x has two integer types: int and
long
 Future Module:
 .Next() function: Python 3.X doesn’t support
“.next()” function.
 In Python 3.x, no long integer type is
specified.
VARIABLES
PYTHON VARIABLES
 A variable is a location in memory used to store some data.
 They are given unique names to differentiate between different memory locations.
 Don't need to declare a variable before using it.
 In Python, simply assign a value to a variable and it will exist. Don’t declare the type of the
variable.
 VARIABLE ASSIGNMENT: We use the assignment operator (=) to assign values to a variable.
 MULTIPLE ASSIGNMENT: In Python, multiple assignments can be made in a single statement.
 We can assign the same value to multiple variables at once.
Assignment
operator
NUMBERS
 Number data types store numeric values.
 They are immutable data types.
 Number objects are created when you assign a value to them.
 We can delete the reference to a number object by using the del statement.
 Syntax: del var1[,var2[,var3[...., varN]]]]
 We can delete a single object or multiple objects by using the del statement.
NUMBERS
 Integer numbers: Integers can be of any length, it is only limited by the
memory available. They are positive or negative whole numbers with no
decimal point.
 Floating point number : It is accurate up to 15 decimal places.
 Complex numbers : These are written in the form, x + yj, where x is the
real part and y is the imaginary part.
 Examples:
Integer
no:
Floating point
no:
Complex
number
EXAMPLES OF NUMBER
 In interactive mode, the last printed expression is assigned to the variable _
 Example:
 Division (/) always returns a float.
 To get an integer result, use floor division (//)
 To calculate the remainder you can use %:
NUMBERS
 Abs(): returns the absolute value of x i.e. the positive distance between x and zero.
 Ceil() : returns the ceiling value of x i.e. the smallest integer not less than x.
 EXP(): returns exponential of x: (e power x).
 Fabs(): returns the absolute value of x. fabs() is defined in math module and
works only on float and integer number.
NUMBERS
• Floor(): returns the floor of x i.e. the largest integer not greater than x.
• Log(): returns the natural logarithm of x.
• Log10(): returns base-10 logarithm of x for x > 0.
• Max(): returns the largest of its arguments
• There are many more functions that perform mathematical operations on
numbers.
NUMBERS
Control Flow And Loops
Various control statements are:
 if and else
 Elif
For
Range
While
Break
Continue
IF AND ELSE STATEMENT
• The syntax for if statement in python are:
• For example:
if (condition): #execution of an if statement
statement1
statement2
else: #execution of an else statement
statement1
statement2
• If we use else statement without using if statement then it will raise an error.
Example of If And Else
Output:
Elif statement
• Elif statement is similar to the else if statement used in c or c++.
• Elif statement is a combination of else and if statement.
• Syntax: if (condition):
statement1
statement2
elif (condition): # elif is a combination of else if
statement3
statement4
else:
statement5
• There can be zero or more elif parts, and the else part is optional. The keyword
‘elif ‘ is short for ‘else if’, and is useful to avoid excessive indentation.
Example of Elif statement
Output:
For Statement
 The for statement in Python differs from in C or C++.
 Python’s for statement iterates over the items of any sequence , in the order that
they appear in the sequence.
 Syntax:
for i in m:
// repeat body for each item in m
Examples of For statement
Output: Output
Example 2:Example1:
Range Function
 Range function is used If we do not want to iterate over a sequence of numbers.
 Range function produces the sequences of values ie i,i+1,……….j-1 if it range(i,j).
 If range(i,j,k) then it increments by k that is i, i+k,……………………….,i+nk.
 Sequence produced by a range is not a list, use list(range(..)) to get a list.
 Why does range(i ,j) stops at j-1?
 to make it easier to process lists
 To iterate over the indices of a sequence, you can combine range() and len() as
follows:
Examples Of Range Function
WHILE LOOP
• While loop in Python is used to iterate over a block of code as long as the test
expression(condition) is true.
• Syntax: while condition:
statement(s) //repeat body till condition becomes false
• Loop might not ever run: When the condition is tested and the result is false then
the loop body will be skipped and the first statement after the while loop is executed.
• Example:
output:
Break Statement
 The break statement in python terminates the current loop and resumes
execution at the next statement , just like break statement in c.
 The break statement can be used in both for and while loops.
Output:
Continue Statement
• Continue statement in Python returns the control to the beginning of the while or
for loop. The continue statement rejects all the remaining statement in the current
iteration of the loop and moves the control back to the top of the loop.
Output:
Pass Statement
 The pass statement is used in Python when statement is required but you do not
want any command or code to execute.
 The pass statement is a null operation means nothing happens when it executes.
Suppose we have a loop or function that is not implemented yet , but we want to
implement it in future. They cannot have an empty body.
 Pass statement is there to create minimal classes.
 It is useful when you have created a code block but it is no longer required.
Comment statement is ignored by interpreter entirely and pass is not ignored.
 Example: output
VARIABLES
CONTRIBUTERS

More Related Content

PPTX
AI programming languages
PDF
Lecture: Regular Expressions and Regular Languages
PPTX
Beginning Python Programming
PDF
TensorFlow and Keras: An Overview
PPTX
Best First Search.pptx
PPTX
Pytorch
PDF
Introduction to TensorFlow Lite
PPTX
Compiler design
AI programming languages
Lecture: Regular Expressions and Regular Languages
Beginning Python Programming
TensorFlow and Keras: An Overview
Best First Search.pptx
Pytorch
Introduction to TensorFlow Lite
Compiler design

What's hot (20)

PPTX
Deep learning.pptx
PDF
Learning Python with PyCharm EDU
PPTX
Compiler design syntax analysis
PPTX
Gpu with cuda architecture
PPTX
Genetic Algorithm
PPTX
Fine-tuning Large Language Models by Dmitry Balabka
PPTX
An Introduction to Soft Computing
PPTX
Introduction to deep learning
PPTX
KERAS Python Tutorial
PDF
Finite fields
PPTX
NLP_KASHK:Text Normalization
PPT
Module4 lex and yacc.ppt
PDF
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
PDF
Genetic Algorithms Made Easy
PPTX
Python training
PPTX
Basics of python
PPTX
Lossless Compression
PDF
Unit 1-problem solving with algorithm
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
POWER OF PYTHON PROGRAMMING LANGUAGE
Deep learning.pptx
Learning Python with PyCharm EDU
Compiler design syntax analysis
Gpu with cuda architecture
Genetic Algorithm
Fine-tuning Large Language Models by Dmitry Balabka
An Introduction to Soft Computing
Introduction to deep learning
KERAS Python Tutorial
Finite fields
NLP_KASHK:Text Normalization
Module4 lex and yacc.ppt
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
Genetic Algorithms Made Easy
Python training
Basics of python
Lossless Compression
Unit 1-problem solving with algorithm
Algorithms Lecture 2: Analysis of Algorithms I
POWER OF PYTHON PROGRAMMING LANGUAGE
Ad

Similar to Introduction to Python Part-1 (20)

PPTX
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
PDF
Python Decision Making And Loops.pdf
PPTX
Introduction to Python for Data Science and Machine Learning
PPTX
Unit - 2 CAP.pptx
PDF
Python Programming Course Presentations
PPTX
Python Session - 4
PDF
Unit 1- Part-2-Control and Loop Statements.pdf
PPTX
Python
PDF
GE3151 UNIT II Study material .pdf
PDF
Python revision tour i
DOCX
Python interview questions and answers
PPTX
Introduction to Python Programming .pptx
PDF
Python interview questions and answers
PPT
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
PPT
Python slides for the beginners to learn
PPT
Py-Slides-1.ppt1234444444444444444444444444444444444444444
PPT
program on python what is python where it was started by whom started
PPT
Python Over View (Python for mobile app Devt)1.ppt
PPTX
MODULE hdsfsf gefegsfs wfefwfwfg etegeg.pptx
PPT
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
Python Decision Making And Loops.pdf
Introduction to Python for Data Science and Machine Learning
Unit - 2 CAP.pptx
Python Programming Course Presentations
Python Session - 4
Unit 1- Part-2-Control and Loop Statements.pdf
Python
GE3151 UNIT II Study material .pdf
Python revision tour i
Python interview questions and answers
Introduction to Python Programming .pptx
Python interview questions and answers
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
Python slides for the beginners to learn
Py-Slides-1.ppt1234444444444444444444444444444444444444444
program on python what is python where it was started by whom started
Python Over View (Python for mobile app Devt)1.ppt
MODULE hdsfsf gefegsfs wfefwfwfg etegeg.pptx
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Ad

More from Devashish Kumar (7)

PPTX
Python: Data Visualisation
PPTX
Pandas csv
PPTX
Data Analysis packages
PPTX
Data Analysis in Python-NumPy
PPTX
Functions in python slide share
PPTX
Data Structures in Python
PPTX
Cloud Computing Introductory-1
Python: Data Visualisation
Pandas csv
Data Analysis packages
Data Analysis in Python-NumPy
Functions in python slide share
Data Structures in Python
Cloud Computing Introductory-1

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Complications of Minimal Access Surgery at WLH
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
master seminar digital applications in india
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Pre independence Education in Inndia.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial disease of the cardiovascular and lymphatic systems
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Complications of Minimal Access Surgery at WLH
O5-L3 Freight Transport Ops (International) V1.pdf
PPH.pptx obstetrics and gynecology in nursing
master seminar digital applications in india
01-Introduction-to-Information-Management.pdf
Cell Types and Its function , kingdom of life
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Anesthesia in Laparoscopic Surgery in India
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf

Introduction to Python Part-1

  • 1. One Day Workshop on Python Devashish Kumar Faculty-IT iNurture
  • 3. Programming Language  A programming language is a notation for writing programs.  A programming language is a computer language designed to communicate instructions to a machine, particularly a computer.  Programming languages can be used to create programs, to control the behaviour of a machine or to express algorithms.  Various programming languages are such as: c , c++ , R, java, C# , ruby , python etc.
  • 4. What is Python ? Python is a high level programming language which is: Interpreted Interactive Object-Oriented Dynamic programming language Open source model
  • 5. WHY PYTHON ? Python is nowadays widely used as an programming language. It has :-  Simple syntax  One-Line command  English like commands(easily readable)  Dynamically Typed  Easily Indentable  Intuitive data structures like tuples, sets, dictionaries,strings,lists etc
  • 6. Applications of Python language Python language used in: – Web Development – Database programming – Game Development – Scientific Computing – Web Framework – Molecular Biology
  • 7. WHY 2.7 RELEASE AFTER 3.X ? • Version 2.X has an awful quantity of useful libraries that haven’t been ported to 3.X version. • Current Linux distributions and Macs are still using 2.x as default. Some are phasing out Python 2 as preinstalled default. • Python 3 already broadly supports creating GUI applications, with Tkinter ,etc. in the standard library. • Python 2.7 provides a stable and a supported base platform for production system that have not yet been ported to Python 3.
  • 8.  In Python 2.X, range() and xrange() function is used for iterating and range() function behaves as it is a list.  In Python 2.X, data type returned is in int,char etc.  In python 2.X, no TypeError is raised if we try to compare unorderable type.  Handling exception: In python 2.X, for handling exception in the syntax we use comma instead of ‘as’.  In python 3.X, xrange() function is not used, it gives name error and range doesnot behave as a list.  In python 3.x, data type returned is in class.  In python 3.X, TypeError is raised as warning if we try to compare unorderable type.  In python 3.X, for handling exception in the syntax we use ‘as’ keyword.
  • 9.  Packages like NumPy and SciPy, Django,Flask,CherryPy and Pyramid is not included in python 2.X.  Integer Division: Python 2.X treats numbers that you type without any digit after the decimal point as integers,which can lead to some unexpected results.  Raising Exceptions:  List comprehension loop variables:  Packages like NumPy and SciPy, Django,Flask,CherryPy and Pyramid is ported to python 3.X .  Python 3.X evaluates “3/2” as 1.5 by default,which is more intuitive for programmer.  Raising exceptions:  List comprehension loop variables:
  • 10.  Future_module: this module is used to help in migration.  .Next() function: Python 2.X supports .next() function.  Output:  Python 2.x has two integer types: int and long  Future Module:  .Next() function: Python 3.X doesn’t support “.next()” function.  In Python 3.x, no long integer type is specified.
  • 12. PYTHON VARIABLES  A variable is a location in memory used to store some data.  They are given unique names to differentiate between different memory locations.  Don't need to declare a variable before using it.  In Python, simply assign a value to a variable and it will exist. Don’t declare the type of the variable.  VARIABLE ASSIGNMENT: We use the assignment operator (=) to assign values to a variable.  MULTIPLE ASSIGNMENT: In Python, multiple assignments can be made in a single statement.  We can assign the same value to multiple variables at once. Assignment operator
  • 13. NUMBERS  Number data types store numeric values.  They are immutable data types.  Number objects are created when you assign a value to them.  We can delete the reference to a number object by using the del statement.  Syntax: del var1[,var2[,var3[...., varN]]]]  We can delete a single object or multiple objects by using the del statement.
  • 14. NUMBERS  Integer numbers: Integers can be of any length, it is only limited by the memory available. They are positive or negative whole numbers with no decimal point.  Floating point number : It is accurate up to 15 decimal places.  Complex numbers : These are written in the form, x + yj, where x is the real part and y is the imaginary part.  Examples: Integer no: Floating point no: Complex number
  • 15. EXAMPLES OF NUMBER  In interactive mode, the last printed expression is assigned to the variable _  Example:  Division (/) always returns a float.  To get an integer result, use floor division (//)  To calculate the remainder you can use %:
  • 16. NUMBERS  Abs(): returns the absolute value of x i.e. the positive distance between x and zero.  Ceil() : returns the ceiling value of x i.e. the smallest integer not less than x.  EXP(): returns exponential of x: (e power x).  Fabs(): returns the absolute value of x. fabs() is defined in math module and works only on float and integer number.
  • 17. NUMBERS • Floor(): returns the floor of x i.e. the largest integer not greater than x. • Log(): returns the natural logarithm of x. • Log10(): returns base-10 logarithm of x for x > 0. • Max(): returns the largest of its arguments • There are many more functions that perform mathematical operations on numbers.
  • 19. Control Flow And Loops Various control statements are:  if and else  Elif For Range While Break Continue
  • 20. IF AND ELSE STATEMENT • The syntax for if statement in python are: • For example: if (condition): #execution of an if statement statement1 statement2 else: #execution of an else statement statement1 statement2 • If we use else statement without using if statement then it will raise an error.
  • 21. Example of If And Else Output:
  • 22. Elif statement • Elif statement is similar to the else if statement used in c or c++. • Elif statement is a combination of else and if statement. • Syntax: if (condition): statement1 statement2 elif (condition): # elif is a combination of else if statement3 statement4 else: statement5 • There can be zero or more elif parts, and the else part is optional. The keyword ‘elif ‘ is short for ‘else if’, and is useful to avoid excessive indentation.
  • 23. Example of Elif statement Output:
  • 24. For Statement  The for statement in Python differs from in C or C++.  Python’s for statement iterates over the items of any sequence , in the order that they appear in the sequence.  Syntax: for i in m: // repeat body for each item in m
  • 25. Examples of For statement Output: Output Example 2:Example1:
  • 26. Range Function  Range function is used If we do not want to iterate over a sequence of numbers.  Range function produces the sequences of values ie i,i+1,……….j-1 if it range(i,j).  If range(i,j,k) then it increments by k that is i, i+k,……………………….,i+nk.  Sequence produced by a range is not a list, use list(range(..)) to get a list.  Why does range(i ,j) stops at j-1?  to make it easier to process lists  To iterate over the indices of a sequence, you can combine range() and len() as follows:
  • 27. Examples Of Range Function
  • 28. WHILE LOOP • While loop in Python is used to iterate over a block of code as long as the test expression(condition) is true. • Syntax: while condition: statement(s) //repeat body till condition becomes false • Loop might not ever run: When the condition is tested and the result is false then the loop body will be skipped and the first statement after the while loop is executed. • Example: output:
  • 29. Break Statement  The break statement in python terminates the current loop and resumes execution at the next statement , just like break statement in c.  The break statement can be used in both for and while loops. Output:
  • 30. Continue Statement • Continue statement in Python returns the control to the beginning of the while or for loop. The continue statement rejects all the remaining statement in the current iteration of the loop and moves the control back to the top of the loop. Output:
  • 31. Pass Statement  The pass statement is used in Python when statement is required but you do not want any command or code to execute.  The pass statement is a null operation means nothing happens when it executes. Suppose we have a loop or function that is not implemented yet , but we want to implement it in future. They cannot have an empty body.  Pass statement is there to create minimal classes.  It is useful when you have created a code block but it is no longer required. Comment statement is ignored by interpreter entirely and pass is not ignored.  Example: output