SlideShare una empresa de Scribd logo
1 de 25
Introduction to Python
Session 1
Named after Monty Python-British comedy group
Python is a general-purpose interpreted, interactive, object-oriented, and high-level
programming language. It was created by Guido van Rossum during 1985- 1990.
Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-
68, SmallTalk, and Unix shell and other scripting languages.
Python’s elegant syntax and dynamic typing, together with its interpreted nature, make
it an ideal language for scripting and rapid application development in many areas on
most platforms.
The Python interpreter and the extensive standard library are freely available in source
or binary form for all major platforms from the Python Web site, https://www.python.org/
Professionally, Python is great for backend web development, data analysis, artificial
intelligence, and scientific computing. Many developers have also used Python to build
productivity tools, games, and desktop apps.
• Scripting and Automation
It is a very useful capability that allows you to type in a program and to have it
executed immediately in an interactive mode.
The code is written in the form of scripts and get executed
Machine reads and interprets the code
Error checking is done during Runtime
Once the code is checked, it can be used several times. So by automation, you can
automate certain tasks in a program.
Why Python
Data Science
Python is the leading language of many data scientist.
For years, academic scholars and private researchers were using the MATLAB
language for scientific research but it all started to change with the release of
Python numerical engines such as ‘Numpy’ and ‘Pandas’.
Computer Graphics
Python is largely used in small, large, online or offline projects.
It is used to build GUI and desktop applications.
It uses ‘Tkinter‘ library to provide fast & easy way to create applications.
Artificial Intelligence
You can actually make a machine mimic the human brain which has the power to
think, analyze and make decisions.
Furthermore, libraries such as Keras and TensorFlow bring machine learning
functionality into the mix.
It gives the ability to learn without being explicitly programmed. Also, we have
libraries such as openCv that helps computer vision or image recognition.
Web Development
Python has an array of frameworks for developing websites.
The popular frameworks are Django, Flask, Pylons etc. Since these frameworks
are written in Python, its the core reason which makes the code a lot faster and
stable.
We can also perform web scraping where you can fetch details from any other
websites.
Portable & Extensible
The portable and extensible properties of Python allow you to perform cross-
language operations seamlessly.
Python is supported by most platforms present in the industry today ranging from
Windows to Linux to Macintosh, Solaris, Play station, among others.
Simple & Easy To Learn
• Python is Free & open source
• High-level
• Interpreted
• Blessed with large community
Installing Python
Python is preinstalled on most Unix or Linux
systems.
But for Windows Operating Systems user
can download from the
https://www.python.org/downloads/
From the link, download the latest version of
python IDE and install.
After Installing the Python go to start menu
you will find Python command line and IDLE
Python GUI.
Python Code Execution
Source code is translated to byte code, which is then run by the Python virtual
machine.
Code is automatically compiled but then it is interpreted.
Local Environment Setup
Open a terminal window and type "python" to find out if it is already installed and
which version is installed.
Setting up PATH
Programs and other executable files can be in many directories, so operating
systems provide a search path that lists the directories that the OS searches for
executables.
The path is stored in an environment variable, which is a named string maintained by
the operating system. This variable contains information available to the command
shell and other programs.
The path variable is named as PATH in Unix or Path in Windows
Setting path at Windows
To add the Python directory to the path for a particular session in Windows −
At the command prompt − type path %path%;C:Python and press Enter.
Note − C:Python is the path of the Python directory
Interactive Mode and Script Mode are the two main modes which are used in
Python Programming Language.
The basic differences between these two modes are as follows:
Interactive mode is used when an user wants to run one single line or one block
of code. It runs very quickly and gives the output instantly.
Example: Python command line.
Script Mode, on the other hand , is used when the user is working with more than
one single code or a block of code.
Example: IDLE Python GUI
Python Identifiers
A Python identifier is a name used to identify a variable, function, class, module or
other object.
An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero
or more letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and % within identifiers.
Python is a case sensitive programming language. Thus, a and A are two different
identifiers in Python.
Here are naming conventions for Python identifiers −
• Class names start with an uppercase letter. All other identifiers start with a
lowercase letter.
• Starting an identifier with a single leading underscore indicates that the identifier
is private.
• Starting an identifier with two leading underscores indicates a strongly private
identifier.
• If the identifier also ends with two trailing underscores, the identifier is a
language-defined special name
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
These are reserved words and you cannot use them as constant or variable or any
other identifier names. All the Python keywords contain lowercase letters only.
Python uses indentation for blocks, instead of curly braces.
Both tabs and spaces are supported, but the standard indentation requires
standard Python code to use four spaces.
Lines and Indentation
if True:
print "True"
else:
print "False"
Thus, in Python all the continuous lines indented with same number of spaces would
form a block.
Comments in Python
A hash sign (#) that is not inside a string literal begins a comment.
All characters after the # and up to the end of the physical line are part of the
comment and the Python interpreter ignores them.
# First comment statement
print "Hello, Class!" # second comment
Output : Hello Class
Triple-quoted string is also ignored by Python interpreter and can be used as a
multiline comments:
'''
This is a multiline
comment.
'''
•
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Swapping of 2 Nos
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)

Más contenido relacionado

Similar a Session-1_Introduction to Python.pptx

introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data sciencebhavesh lande
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxManohar k
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1Kirti Verma
 
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Niraj Bharambe
 
Python Applications by The Knowledge Academy.docx
Python Applications by The Knowledge Academy.docxPython Applications by The Knowledge Academy.docx
Python Applications by The Knowledge Academy.docxAbhinavSharma309481
 
What is Python.pptx
What is Python.pptxWhat is Python.pptx
What is Python.pptxMalluKomar
 
session5-Getting stated with Python.pdf
session5-Getting stated with Python.pdfsession5-Getting stated with Python.pdf
session5-Getting stated with Python.pdfAyushDutta32
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfVaibhavKumarSinghkal
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonMohammed Rafi
 
Python Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & TechPython Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & TechRamanamurthy Banda
 
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfCSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfAbdulmalikAhmadLawan2
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of pythonBijuAugustian
 

Similar a Session-1_Introduction to Python.pptx (20)

introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
01 python introduction
01 python introduction 01 python introduction
01 python introduction
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docx
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1
 
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
 
Python Applications by The Knowledge Academy.docx
Python Applications by The Knowledge Academy.docxPython Applications by The Knowledge Academy.docx
Python Applications by The Knowledge Academy.docx
 
What is Python.pptx
What is Python.pptxWhat is Python.pptx
What is Python.pptx
 
Python Intro
Python IntroPython Intro
Python Intro
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
session5-Getting stated with Python.pdf
session5-Getting stated with Python.pdfsession5-Getting stated with Python.pdf
session5-Getting stated with Python.pdf
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
Python Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & TechPython Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & Tech
 
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfCSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
Python for Beginners.docx
Python for Beginners.docxPython for Beginners.docx
Python for Beginners.docx
 

Último

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Último (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Session-1_Introduction to Python.pptx

  • 2. Named after Monty Python-British comedy group
  • 3. Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990. Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol- 68, SmallTalk, and Unix shell and other scripting languages. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, https://www.python.org/ Professionally, Python is great for backend web development, data analysis, artificial intelligence, and scientific computing. Many developers have also used Python to build productivity tools, games, and desktop apps.
  • 4. • Scripting and Automation It is a very useful capability that allows you to type in a program and to have it executed immediately in an interactive mode. The code is written in the form of scripts and get executed Machine reads and interprets the code Error checking is done during Runtime Once the code is checked, it can be used several times. So by automation, you can automate certain tasks in a program. Why Python
  • 5. Data Science Python is the leading language of many data scientist. For years, academic scholars and private researchers were using the MATLAB language for scientific research but it all started to change with the release of Python numerical engines such as ‘Numpy’ and ‘Pandas’. Computer Graphics Python is largely used in small, large, online or offline projects. It is used to build GUI and desktop applications. It uses ‘Tkinter‘ library to provide fast & easy way to create applications.
  • 6. Artificial Intelligence You can actually make a machine mimic the human brain which has the power to think, analyze and make decisions. Furthermore, libraries such as Keras and TensorFlow bring machine learning functionality into the mix. It gives the ability to learn without being explicitly programmed. Also, we have libraries such as openCv that helps computer vision or image recognition. Web Development Python has an array of frameworks for developing websites. The popular frameworks are Django, Flask, Pylons etc. Since these frameworks are written in Python, its the core reason which makes the code a lot faster and stable. We can also perform web scraping where you can fetch details from any other websites.
  • 7. Portable & Extensible The portable and extensible properties of Python allow you to perform cross- language operations seamlessly. Python is supported by most platforms present in the industry today ranging from Windows to Linux to Macintosh, Solaris, Play station, among others. Simple & Easy To Learn • Python is Free & open source • High-level • Interpreted • Blessed with large community
  • 8.
  • 9. Installing Python Python is preinstalled on most Unix or Linux systems. But for Windows Operating Systems user can download from the https://www.python.org/downloads/ From the link, download the latest version of python IDE and install. After Installing the Python go to start menu you will find Python command line and IDLE Python GUI.
  • 10. Python Code Execution Source code is translated to byte code, which is then run by the Python virtual machine. Code is automatically compiled but then it is interpreted.
  • 11. Local Environment Setup Open a terminal window and type "python" to find out if it is already installed and which version is installed.
  • 12. Setting up PATH Programs and other executable files can be in many directories, so operating systems provide a search path that lists the directories that the OS searches for executables. The path is stored in an environment variable, which is a named string maintained by the operating system. This variable contains information available to the command shell and other programs. The path variable is named as PATH in Unix or Path in Windows Setting path at Windows To add the Python directory to the path for a particular session in Windows − At the command prompt − type path %path%;C:Python and press Enter. Note − C:Python is the path of the Python directory
  • 13. Interactive Mode and Script Mode are the two main modes which are used in Python Programming Language. The basic differences between these two modes are as follows: Interactive mode is used when an user wants to run one single line or one block of code. It runs very quickly and gives the output instantly. Example: Python command line. Script Mode, on the other hand , is used when the user is working with more than one single code or a block of code. Example: IDLE Python GUI
  • 14.
  • 15. Python Identifiers A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9). Python does not allow punctuation characters such as @, $, and % within identifiers. Python is a case sensitive programming language. Thus, a and A are two different identifiers in Python.
  • 16. Here are naming conventions for Python identifiers − • Class names start with an uppercase letter. All other identifiers start with a lowercase letter. • Starting an identifier with a single leading underscore indicates that the identifier is private. • Starting an identifier with two leading underscores indicates a strongly private identifier. • If the identifier also ends with two trailing underscores, the identifier is a language-defined special name
  • 17. and exec not assert finally or break for pass class from print continue global raise def if return del import try elif in while else is with except lambda yield These are reserved words and you cannot use them as constant or variable or any other identifier names. All the Python keywords contain lowercase letters only.
  • 18. Python uses indentation for blocks, instead of curly braces. Both tabs and spaces are supported, but the standard indentation requires standard Python code to use four spaces. Lines and Indentation if True: print "True" else: print "False" Thus, in Python all the continuous lines indented with same number of spaces would form a block.
  • 19. Comments in Python A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and the Python interpreter ignores them. # First comment statement print "Hello, Class!" # second comment Output : Hello Class Triple-quoted string is also ignored by Python interpreter and can be used as a multiline comments: ''' This is a multiline comment. '''
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. num1 = 1.5 num2 = 6.3 # Add two numbers sum = num1 + num2 # Display the sum print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) Swapping of 2 Nos x = 5 y = 10 x, y = y, x print("x =", x) print("y =", y)