SlideShare a Scribd company logo
Swipe
Python Syntax
The syntax of the Python programming language is
the set of rules that defines how a Python program
will be written and interpreted (by both the
runtime system and by human readers).
The Python language has many similarities to Perl,
C, and Java. However, there are some definite
differences between the languages.
Python syntax
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, Manpower
and manpower are two different identifiers in
Python.
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.
Naming conventions for Python identifiers
The following list shows the Python keywords.
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.
Reserved Words
and
exec
not
assert
finally
or
break
for
pass
class
from
print
Python provides no braces to indicate blocks of
code for class and function definitions or flow
control. Blocks of code are denoted by line
indentation, which is rigidly enforced.
The number of spaces in the indentation is variable,
but all statements within the block must be
indented the same amount. For example −
Lines and Indentation
if True:
print "True"
else:
print "False"
Statements in Python typically end with a new line.
Python does, however, allow the use of the line
continuation character () to denote that the line
should continue. For example −
Multi-Line Statements
total = item_one + 
item_two + 
item_three
Statements contained within the [], {}, or () brackets
do not need to use the line continuation character.
For example −
days = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday']
Python accepts single ('), double (") and triple (''' or
""") quotes to denote string literals, as long as the
same type of quote starts and ends the string.
The triple quotes are used to span the string across
multiple lines. For example, all the following are
legal −
Quotation in Python
word = 'word'
sentence = "This is a sentence."
paragraph = """This is a paragraph. It is
made up of multiple lines and sentences.
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.
Comments in Python
#!/usr/bin/python# First
commentprint "Hello, Python!" #
second comment
Hello, Python!
Input
Output
The semicolon ( ; ) allows multiple statements on
the single line given that neither statement starts a
new code block. Here is a sample snip using the
semicolon −
Multiple Statements on a Single Line
import sys; x = 'foo'; sys.stdout.write(x + 'n')
A group of individual statements, which make a
single code block are called suites in Python.
Compound or complex statements, such as if, while,
def, and class require a header line and a suite.
Header lines begin the statement (with the
keyword) and terminate with a colon ( : ) and are
followed by one or more lines which make up the
suite. For example −
Multiple Statement Groups as Suites
if expression :
suite
elif expression :
suite
else :
suite
Python Variable Types
Python Operations
Stay Tuned with
Topics for next Post
Ad

More Related Content

What's hot (20)

Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
Mohammed Sikander
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
Samir Mohanty
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
Siddique Ibrahim
 
Python-FileHandling.pptx
Python-FileHandling.pptxPython-FileHandling.pptx
Python-FileHandling.pptx
Karudaiyar Ganapathy
 
Python for loop
Python for loopPython for loop
Python for loop
Aishwarya Deshmukh
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
Sharath Ankrajegowda
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
Explore Skilled
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Python-DataAbstarction.pptx
Python-DataAbstarction.pptxPython-DataAbstarction.pptx
Python-DataAbstarction.pptx
Karudaiyar Ganapathy
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Python modules
Python modulesPython modules
Python modules
Shanmugapriya Dineshbabu
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Dipankar Achinta
 

Similar to Python syntax (20)

Python quick guide
Python quick guidePython quick guide
Python quick guide
Hasan Bisri
 
Basic Syntax of python thats help to.pptx
Basic Syntax of python thats help to.pptxBasic Syntax of python thats help to.pptx
Basic Syntax of python thats help to.pptx
MdMujahidHasan1
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
Jaya Kumari
 
Introduction to Python Programming .pptx
Introduction to  Python Programming .pptxIntroduction to  Python Programming .pptx
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
AkramWaseem
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
Dominik KAszubowski
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
Praveen M Jigajinni
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
StefanoTermini3
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
Aswin Krishnamoorthy
 
Python Programming for problem solving.pptx
Python Programming for problem solving.pptxPython Programming for problem solving.pptx
Python Programming for problem solving.pptx
NishaM41
 
Python unit 1 (1).pptx
Python unit 1 (1).pptxPython unit 1 (1).pptx
Python unit 1 (1).pptx
AdityaPratapSingh17056
 
3-Python Python oho pytho hdiwefjhdsjhds
3-Python Python oho pytho hdiwefjhdsjhds3-Python Python oho pytho hdiwefjhdsjhds
3-Python Python oho pytho hdiwefjhdsjhds
hardikbhagwaria83
 
Python comments and variables.pptx
Python comments and variables.pptxPython comments and variables.pptx
Python comments and variables.pptx
adityakumawat625
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Introduction on basic python and it's application
Introduction on basic python and it's applicationIntroduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
 
Biswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptxBiswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptx
BiswambarBehera5
 
Python
PythonPython
Python
Dr. SURBHI SAROHA
 
Chapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptxChapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptx
MrSaem
 
Python quick guide
Python quick guidePython quick guide
Python quick guide
Hasan Bisri
 
Basic Syntax of python thats help to.pptx
Basic Syntax of python thats help to.pptxBasic Syntax of python thats help to.pptx
Basic Syntax of python thats help to.pptx
MdMujahidHasan1
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
Jaya Kumari
 
Introduction to Python Programming .pptx
Introduction to  Python Programming .pptxIntroduction to  Python Programming .pptx
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
StefanoTermini3
 
Python Programming for problem solving.pptx
Python Programming for problem solving.pptxPython Programming for problem solving.pptx
Python Programming for problem solving.pptx
NishaM41
 
3-Python Python oho pytho hdiwefjhdsjhds
3-Python Python oho pytho hdiwefjhdsjhds3-Python Python oho pytho hdiwefjhdsjhds
3-Python Python oho pytho hdiwefjhdsjhds
hardikbhagwaria83
 
Python comments and variables.pptx
Python comments and variables.pptxPython comments and variables.pptx
Python comments and variables.pptx
adityakumawat625
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Introduction on basic python and it's application
Introduction on basic python and it's applicationIntroduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
 
Biswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptxBiswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptx
BiswambarBehera5
 
Chapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptxChapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptx
MrSaem
 
Ad

More from Learnbay Datascience (20)

Top data science projects
Top data science projectsTop data science projects
Top data science projects
Learnbay Datascience
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
Learnbay Datascience
 
Python my SQL - create database
Python my SQL - create databasePython my SQL - create database
Python my SQL - create database
Learnbay Datascience
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
Learnbay Datascience
 
Python - mySOL
Python - mySOLPython - mySOL
Python - mySOL
Learnbay Datascience
 
AI - Issues and Terminology
AI - Issues and TerminologyAI - Issues and Terminology
AI - Issues and Terminology
Learnbay Datascience
 
AI - Fuzzy Logic Systems
AI - Fuzzy Logic SystemsAI - Fuzzy Logic Systems
AI - Fuzzy Logic Systems
Learnbay Datascience
 
AI - working of an ns
AI - working of an nsAI - working of an ns
AI - working of an ns
Learnbay Datascience
 
Artificial Intelligence- Neural Networks
Artificial Intelligence- Neural NetworksArtificial Intelligence- Neural Networks
Artificial Intelligence- Neural Networks
Learnbay Datascience
 
AI - Robotics
AI - RoboticsAI - Robotics
AI - Robotics
Learnbay Datascience
 
Applications of expert system
Applications of expert systemApplications of expert system
Applications of expert system
Learnbay Datascience
 
Components of expert systems
Components of expert systemsComponents of expert systems
Components of expert systems
Learnbay Datascience
 
Artificial intelligence - expert systems
 Artificial intelligence - expert systems Artificial intelligence - expert systems
Artificial intelligence - expert systems
Learnbay Datascience
 
AI - natural language processing
AI - natural language processingAI - natural language processing
AI - natural language processing
Learnbay Datascience
 
Ai popular search algorithms
Ai   popular search algorithmsAi   popular search algorithms
Ai popular search algorithms
Learnbay Datascience
 
AI - Agents & Environments
AI - Agents & EnvironmentsAI - Agents & Environments
AI - Agents & Environments
Learnbay Datascience
 
Artificial intelligence - research areas
Artificial intelligence - research areasArtificial intelligence - research areas
Artificial intelligence - research areas
Learnbay Datascience
 
Artificial intelligence composed
Artificial intelligence composedArtificial intelligence composed
Artificial intelligence composed
Learnbay Datascience
 
Artificial intelligence intelligent systems
Artificial intelligence   intelligent systemsArtificial intelligence   intelligent systems
Artificial intelligence intelligent systems
Learnbay Datascience
 
Applications of ai
Applications of aiApplications of ai
Applications of ai
Learnbay Datascience
 
Artificial Intelligence- Neural Networks
Artificial Intelligence- Neural NetworksArtificial Intelligence- Neural Networks
Artificial Intelligence- Neural Networks
Learnbay Datascience
 
Artificial intelligence - expert systems
 Artificial intelligence - expert systems Artificial intelligence - expert systems
Artificial intelligence - expert systems
Learnbay Datascience
 
Artificial intelligence - research areas
Artificial intelligence - research areasArtificial intelligence - research areas
Artificial intelligence - research areas
Learnbay Datascience
 
Artificial intelligence intelligent systems
Artificial intelligence   intelligent systemsArtificial intelligence   intelligent systems
Artificial intelligence intelligent systems
Learnbay Datascience
 
Ad

Recently uploaded (20)

Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 

Python syntax

  • 2. The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted (by both the runtime system and by human readers). The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. Python syntax
  • 3. 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, Manpower and manpower are two different identifiers in Python. Python Identifiers
  • 4. 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. Naming conventions for Python identifiers
  • 5. The following list shows the Python keywords. 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. Reserved Words and exec not assert finally or break for pass class from print
  • 6. Python provides no braces to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced. The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount. For example − Lines and Indentation if True: print "True" else: print "False"
  • 7. Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character () to denote that the line should continue. For example − Multi-Line Statements total = item_one + item_two + item_three Statements contained within the [], {}, or () brackets do not need to use the line continuation character. For example − days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
  • 8. Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string. The triple quotes are used to span the string across multiple lines. For example, all the following are legal − Quotation in Python word = 'word' sentence = "This is a sentence." paragraph = """This is a paragraph. It is made up of multiple lines and sentences.
  • 9. 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. Comments in Python #!/usr/bin/python# First commentprint "Hello, Python!" # second comment Hello, Python! Input Output
  • 10. The semicolon ( ; ) allows multiple statements on the single line given that neither statement starts a new code block. Here is a sample snip using the semicolon − Multiple Statements on a Single Line import sys; x = 'foo'; sys.stdout.write(x + 'n')
  • 11. A group of individual statements, which make a single code block are called suites in Python. Compound or complex statements, such as if, while, def, and class require a header line and a suite. Header lines begin the statement (with the keyword) and terminate with a colon ( : ) and are followed by one or more lines which make up the suite. For example − Multiple Statement Groups as Suites if expression : suite elif expression : suite else : suite
  • 12. Python Variable Types Python Operations Stay Tuned with Topics for next Post