SlideShare a Scribd company logo
1 of 34
PYTHON PROGRAMMING
UNIT
1
RESHMA R
ASSISTANT PROFESSOR
CSE, KAHE
OUTLINE
• PYTHON
• WHY PYTHON?- FEATURES
• ADVANTAGES
• APPLICATIONS
• TOOLS
• INSTALLATION
PYTHON
• Interpreter language, High level language, Dynamic, Garbage Collected language
• Developed by Guido Van Rossum in 1991
• Python Software Foundation
• Official Web Site: https://www.python.org
• Code Readability
• Simple Syntax
• Works quickly and effectively
VERSIONS: PYTHON 2 & PYTHON 3
2020- Python 2.7.15
2021- Python 3.9.7
2000- Python 2
2008- Python 3
WHY PYTHON?-FEATURES
• Object Oriented
• Free/Open Source
• Powerful
• Dynamic typing
• Built-in types and tools
• Library utilities
• Third party utilities (e.g. NumPy, sciPy)
• Automatic memory management
• Portable
• Easy to use and learn
• Interactive
ADVANTAGES
• Enhanced readability
• Uniform indents to delimit blocks of statements instead of curly brackets
• Free and distributed as open-source software
• Available to large programming community
• Support Python libraries for various applications such as web frameworks, mathematical
computing, and data science
• A cross-platform language
• Works on Windows, Linux, Mac, etc.
• Supports multiple programming paradigms
• Imperative, procedural, object-oriented, and functional programming styles
• An extensible language
• Additional functionality through modules and packages of other languages
• Integrated with other languages
APPLICATIONS
• Data Science
• Companies need business insights from mobile data, web data,
sensor data, etc.
TOOLS
INSTALLATION
• Available on https://www.python.org/downloads
• Installed on Windows, Linux, Mac OS and certain other platforms such as IBM
AS/400, iOS, Solaris, etc.
• Windows:
• Web-based installer
• Executable installer
• Embeddable zip files
• After successful installation
• Check the Python installation using command prompt
• type python --version or python -V and press
• If Python installed successfully
• Display the installed version
• C:>python --version
• Python 3.7.0
• Mac OS X
• https://www.python.org/downloads/mac-osx page.
• Download the latest version under the heading Python Releases for Mac OS X.
• Double click on the installer file to start the installation wizard.
• On the installation wizard, click on Continue a few times
• Until you're asked to agree to the software license agreement,
• Click on Agree and finish the installation.
• Linux
• Mostly come up with Python installation
• If Python 3.x is available, run the following command in the Linux terminal:
• $ which python3
• If available, it will return the path to the Python3 executable as
• /usr/local/bin/python3.
• To install Python on Ubuntu 18.04, Ubuntu 20.04 and above,
• Execute the following commands:
• $ sudo apt-get update
• $ sudo apt-get install python3.7 python3-pip
3 STEPS
• Find the interpreter
• Write program
• Run and test
INTERACTIVE SHELL/SCRIPT
PRACTICE
• Lets learn through EXCERCISE
SYNTAX
• Set of rules - defines how a Python program will be written and interpreted
• For example – Grammar in English language
PYTHON LINE STRUCTURE
• Python program comprises logical lines
• NEWLINE token follows each
• Indicates the end of a logical line of Python code
• Interpreter ignores blank lines.
• >>> print("Hi
How are you?")
SyntaxError: EOL while scanning string literal
Error
PYTHON MULTILINE STATEMENTS
• Python does not mandate semicolons
• New line means a new statement
• Sometimes, need to split a statement over two or more lines
• to aid readability
a. Use a backward slash
• >>> print("Hi
how are you?")
b. Put the String in Triple Quotes
• >>> print("""Hi
how are you?""")
• Can distribute a statement without a string across lines.
• >>> a
=
10
>>> print(a)
Output: 10 instead a=10
PYTHON COMMENTS
• Declare a comment using an octothorpe (#)
• >>> #This is a comment
PYTHON DOCSTRINGS
• Documentation string
• Unlike comments, they are more specific
• As a comment, this Python Syntax is used to explain code.
>>> def func():
"""
This function prints out a greeting
"""
print("Hi")
>>> func()
Delimit a docstring using three double-quotes.
PYTHON INDENTATION
• Doesn’t use curly braces to delimit blocks of code
• Indent code under a function, loop, or class.
• >>> if 2>1:
print("2 is the bigger person");
print("But 1 is worthy too");
• Use 4 spaces or tab
PYTHON MULTIPLE STATEMENTS IN ONE
LINE
• Fit in more than one statement on one line.
• >>> a=7;print(a);
PYTHON QUOTATIONS
• Supports single quote and the double quote for string literals
• >>> print('We need a chaperone’);
• >>> print(“We need a chaperone”);
• >>> print(“We need a ‘chaperone’”);
>>> print(“We need a “chaperone””);
>>> print('We need a ‘chaperone’'); ERROR
PYTHON BLANK LINES
• If you leave a line with just whitespace, the interpreter will ignore it.
• Name of a program element - user-defined
• Python syntax uniquely identifies the element
• An identifier may only begin with A-Z, a-z, or an underscore(_).
• This may be followed by letters, digits, and underscores- zero or more.
• Python is case-sensitive. Name and name are two different identifiers.
• A reserved keyword may not be used as an identifier.
PYTHON IDENTIFIERS
LIST OF KEYWORDS
PYTHON VARIABLES
• It is assumed on the basis of the value it holds.
>>> x=10
>>> print(x)
OUTPUT: 10
>>> x='Hello'
>>> print(x)
OUTPUT: Hello
DISCUSS IN
DETAIL LATER…..
PYTHON STRING FORMATTERS
a. % Operator
 To format a string to contain text and values of identifiers
 Use %s where you want a value to appear
 After the string, put a % operator
 Mention the identifiers in parameters
Example:
>>> x=10; printer="HP"
>>> print("I just printed %s pages to the printer %s" % (x, printer))
Output:
I just printed 10 pages to the printer HP
b. Format Method
To format a string in a similar way
At the places, you want to put values
 Put 0,1,2,.. in curly braces.
Call the format method on the string
 Mention the identifiers in the parameters.
Example:
>>> x=10, printer=‘HP’, y=‘Printer’
>>>print("I just printed {0} pages to the printer {1} {2}".format(x, printer,y))
>>> print("I just printed {x} pages to the printer {printer}".format(x=10, printer='HP'))
Output:
I just printed 10 pages to the printer HP Printer
c. f-strings
• Write ‘f’ right before the string
• But outside the quotes used.
>>> print(f"I just printed {x} pages to the printer {printer}")
Output:
I just printed 10 pages to the printer HP
GE3151- PYTHON PROGRAMMING ANNA UNI.pptx

More Related Content

Similar to GE3151- PYTHON PROGRAMMING ANNA UNI.pptx

python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptxArpittripathi45
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxansariparveen06
 
Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxlemonchoos
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdfssuser9a6ca1
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonMohammed Rafi
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of pythonBijuAugustian
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdfgmadhu8
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonSway Wang
 
Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptxpcjoshi02
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPTShivam Gupta
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 

Similar to GE3151- PYTHON PROGRAMMING ANNA UNI.pptx (20)

python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
python into.pptx
python into.pptxpython into.pptx
python into.pptx
 
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
 
Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
python program
python programpython program
python program
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Module-1.pptx
Module-1.pptxModule-1.pptx
Module-1.pptx
 
Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptx
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Python
PythonPython
Python
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 

Recently uploaded

What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsVIEW
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...drjose256
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxMANASINANDKISHORDEOR
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptamrabdallah9
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptjigup7320
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationEmaan Sharma
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxCHAIRMAN M
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Studentskannan348865
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.benjamincojr
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfKira Dess
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Studentskannan348865
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalSwarnaSLcse
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksIJECEIAES
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualBalamuruganV28
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Stationsiddharthteach18
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 

Recently uploaded (20)

What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 

GE3151- PYTHON PROGRAMMING ANNA UNI.pptx

  • 2. OUTLINE • PYTHON • WHY PYTHON?- FEATURES • ADVANTAGES • APPLICATIONS • TOOLS • INSTALLATION
  • 3. PYTHON • Interpreter language, High level language, Dynamic, Garbage Collected language • Developed by Guido Van Rossum in 1991 • Python Software Foundation • Official Web Site: https://www.python.org • Code Readability • Simple Syntax • Works quickly and effectively VERSIONS: PYTHON 2 & PYTHON 3 2020- Python 2.7.15 2021- Python 3.9.7 2000- Python 2 2008- Python 3
  • 4. WHY PYTHON?-FEATURES • Object Oriented • Free/Open Source • Powerful • Dynamic typing • Built-in types and tools • Library utilities • Third party utilities (e.g. NumPy, sciPy) • Automatic memory management • Portable • Easy to use and learn • Interactive
  • 5. ADVANTAGES • Enhanced readability • Uniform indents to delimit blocks of statements instead of curly brackets • Free and distributed as open-source software • Available to large programming community • Support Python libraries for various applications such as web frameworks, mathematical computing, and data science • A cross-platform language • Works on Windows, Linux, Mac, etc. • Supports multiple programming paradigms • Imperative, procedural, object-oriented, and functional programming styles • An extensible language • Additional functionality through modules and packages of other languages • Integrated with other languages
  • 6. APPLICATIONS • Data Science • Companies need business insights from mobile data, web data, sensor data, etc.
  • 8. INSTALLATION • Available on https://www.python.org/downloads • Installed on Windows, Linux, Mac OS and certain other platforms such as IBM AS/400, iOS, Solaris, etc. • Windows: • Web-based installer • Executable installer • Embeddable zip files
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. • After successful installation • Check the Python installation using command prompt • type python --version or python -V and press • If Python installed successfully • Display the installed version • C:>python --version • Python 3.7.0
  • 16. • Mac OS X • https://www.python.org/downloads/mac-osx page. • Download the latest version under the heading Python Releases for Mac OS X. • Double click on the installer file to start the installation wizard. • On the installation wizard, click on Continue a few times • Until you're asked to agree to the software license agreement, • Click on Agree and finish the installation.
  • 17. • Linux • Mostly come up with Python installation • If Python 3.x is available, run the following command in the Linux terminal: • $ which python3 • If available, it will return the path to the Python3 executable as • /usr/local/bin/python3. • To install Python on Ubuntu 18.04, Ubuntu 20.04 and above, • Execute the following commands: • $ sudo apt-get update • $ sudo apt-get install python3.7 python3-pip
  • 18. 3 STEPS • Find the interpreter • Write program • Run and test
  • 20.
  • 21. PRACTICE • Lets learn through EXCERCISE
  • 22. SYNTAX • Set of rules - defines how a Python program will be written and interpreted • For example – Grammar in English language
  • 23. PYTHON LINE STRUCTURE • Python program comprises logical lines • NEWLINE token follows each • Indicates the end of a logical line of Python code • Interpreter ignores blank lines. • >>> print("Hi How are you?") SyntaxError: EOL while scanning string literal Error
  • 24. PYTHON MULTILINE STATEMENTS • Python does not mandate semicolons • New line means a new statement • Sometimes, need to split a statement over two or more lines • to aid readability a. Use a backward slash • >>> print("Hi how are you?") b. Put the String in Triple Quotes • >>> print("""Hi how are you?""") • Can distribute a statement without a string across lines. • >>> a = 10 >>> print(a) Output: 10 instead a=10
  • 25. PYTHON COMMENTS • Declare a comment using an octothorpe (#) • >>> #This is a comment PYTHON DOCSTRINGS • Documentation string • Unlike comments, they are more specific • As a comment, this Python Syntax is used to explain code. >>> def func(): """ This function prints out a greeting """ print("Hi") >>> func() Delimit a docstring using three double-quotes.
  • 26. PYTHON INDENTATION • Doesn’t use curly braces to delimit blocks of code • Indent code under a function, loop, or class. • >>> if 2>1: print("2 is the bigger person"); print("But 1 is worthy too"); • Use 4 spaces or tab PYTHON MULTIPLE STATEMENTS IN ONE LINE • Fit in more than one statement on one line. • >>> a=7;print(a);
  • 27. PYTHON QUOTATIONS • Supports single quote and the double quote for string literals • >>> print('We need a chaperone’); • >>> print(“We need a chaperone”); • >>> print(“We need a ‘chaperone’”); >>> print(“We need a “chaperone””); >>> print('We need a ‘chaperone’'); ERROR
  • 28. PYTHON BLANK LINES • If you leave a line with just whitespace, the interpreter will ignore it. • Name of a program element - user-defined • Python syntax uniquely identifies the element • An identifier may only begin with A-Z, a-z, or an underscore(_). • This may be followed by letters, digits, and underscores- zero or more. • Python is case-sensitive. Name and name are two different identifiers. • A reserved keyword may not be used as an identifier. PYTHON IDENTIFIERS
  • 30. PYTHON VARIABLES • It is assumed on the basis of the value it holds. >>> x=10 >>> print(x) OUTPUT: 10 >>> x='Hello' >>> print(x) OUTPUT: Hello DISCUSS IN DETAIL LATER…..
  • 31. PYTHON STRING FORMATTERS a. % Operator  To format a string to contain text and values of identifiers  Use %s where you want a value to appear  After the string, put a % operator  Mention the identifiers in parameters Example: >>> x=10; printer="HP" >>> print("I just printed %s pages to the printer %s" % (x, printer)) Output: I just printed 10 pages to the printer HP
  • 32. b. Format Method To format a string in a similar way At the places, you want to put values  Put 0,1,2,.. in curly braces. Call the format method on the string  Mention the identifiers in the parameters. Example: >>> x=10, printer=‘HP’, y=‘Printer’ >>>print("I just printed {0} pages to the printer {1} {2}".format(x, printer,y)) >>> print("I just printed {x} pages to the printer {printer}".format(x=10, printer='HP')) Output: I just printed 10 pages to the printer HP Printer
  • 33. c. f-strings • Write ‘f’ right before the string • But outside the quotes used. >>> print(f"I just printed {x} pages to the printer {printer}") Output: I just printed 10 pages to the printer HP

Editor's Notes

  1. Guido Van Rossum conceived Python in the late 1980s. It was released in 1991 at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to the ABC language. He named this language after a popular comedy show called 'Monty Python's Flying Circus' (and not after Python-the snake).
  2. Extensive basic data types are supported e.g., numbers (floating point, complex, and unlimited-length long integers), strings (both ASCII and Unicode), lists, and dictionaries.
  3. Imperative- Statements that change a program's state, No-built in functions, every operation is coded and the code itself specifies how the problem is to be solved Procedural- Programming paradigm built around the idea that programs are sequences of instructions to be executed OOP-Programming paradigm based upon objects (having both data and methods) that aims to incorporate the advantages of modularity and reusability
  4. Check the Add Python 3.7 to PATH checkbox, so that you can execute python scripts from any path. You choose the installation folder or feature by clicking on Customize installation.
  5. Check the Add Python 3.7 to PATH checkbox, so that you can execute python scripts from any path. You choose the installation folder or feature by clicking on Customize installation.