SlideShare a Scribd company logo
1 of 12
UNIT-1(Lesson 2)
Comments, Identifiers and Keywords
COMMENTS
A computer program is a collection of instructions or statements.
A Python program is usually composed of multiple statements. Each statement is composed of one
or a combination of the following:
1.Comments
2.Whitespace characters
3.Tokens
In a computer program, a comment is used to mark a section of code as non-executable.
Comments are mainly used for two purposes:
a) To mark a section of source code as non-executable, so that the Python interpreter ignores it.
b) To provide remarks or an explanation on the working of the given section of code in plain
English, so that a fellow programmer can read the comments and understand the code.
Types of Comments with examples
In Python, there are two types of comments:
1. Single-line comment : It starts with # (also known as the hash or pound character) and the content following # till the
end of that line is a comment.
2. Docstring comment : Content enclosed between triple quotes, either ''' or """.
Below code example demonstrates the usage of comments:
Key points in relation to comments:
1. The # character must be specified at beginning of a comment line.
2. Comments do not nest. Meaning # has no special meaning inside a comment line which starts with #.
3. One cannot write comments inside string literals which are enclosed between single-quotes or double-quotes.
The # character inside a string literal is treated as part of the string's content.
4. In a comment anything written after # in a particular line is ignored by the interpreter. Meaning it does not form part of
the executable code in the program.
Practice Question:
1. Make the following changes in the below code :
Remove the comment on the line which prints "I am a Python Guru"
Add a comment on the line which prints "Python is not cool"
Python provides a way to specify documentation comments, called docstrings. A docstring is a string
literal (plain text usually in English) provided in the source code to document what a particular segment
of code does.
 Python allows the use of both """triple-double-quotes""" or '''triple-single-quotes''' to create docstrings. However,
the Python coding conventions specification recommends us to use """triple-double-quotes""" for consistency.
The main purpose of docstrings in Python is to provide information on what a particular Python object does and
not how it does
According to the Python coding conventions, the docstring should always begin with a capital letter and end with
a period (.)
Example:
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")
Note: docstrings inside modules, classes, functions, members, method definitions, etc. will be
done later
Identifier
An identifier is a name used to identify a variable, function, class, module, or object.
In Python, an identifier is like a noun in English.
Identifier helps in differentiating one entity from the other. For example, name and age which speak of two different aspects are called identifiers.
Python is a case-sensitive programming language. Meaning, Age and age are two different identifiers in Python.
Rules:
1) Identifiers can be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore ( _ ).
Examples:
myClass, var_1, print_this_to_screen, _number are valid Python identifiers.
2) An identifier can start with an alphabet or an underscore (_), but not with a digit.
Examples:
1_variable is invalid, but variable_1 is perfectly fine.
3) Keywords cannot be used as identifiers. (Keywords are reserved words in Python which have a special meaning).
Examples:
def, and, not, for, while, if, else etc.
4) Special symbols like !, @, #, $, % etc. are not allowed in identifiers. Only one special symbol underscore (_) is allowed.
Examples:
company#name, $name, email@id are invalid Python identifiers.
5) Identifiers can be of any length.
Which of the following options are correct?
1. Identifiers are used for identifying entities in a program.
2. We can use any special character like @,#,$ as part of identifiers.
3. 1st_string is a valid identifier.
4. string_1 is valid identifier.
5. Identifiers can be of any length.
A. All are Correct
B. 1,2 and 3 only
C. 1,4 and 5 only
D. 1,3 and 4 only
Which of the following options are correct?
1. Identifiers are used for identifying entities in a program.
2. We can use any special character like @,#,$ as part of identifiers.
3. 1st_string is a valid identifier.
4. string_1 is valid identifier.
5. Identifiers can be of any length.
A. All are Correct
B. 1,2 and 3 only
C. 1,4 and 5 only
D. 1,3 and 4 only
Keywords
Every programming language usually has a set of words know as keywords.
These are reserved words with special meaning and purpose. They are used only for the intended
purpose.
Note : We cannot use a keyword as a variable name, function name or as any other identifier name.
Python 2 has 32 keywords while Python 3.5 has 33 keywords. An extra keyword called nonlocal was
added in Python 3.5. 2 more keywords were added in Python 3.7 making it to 35
Latest version is also having 35 keywords
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or',
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Python provides a way to print the list of keywords in its current version.
import keyword # This statement is used to import keyword module.
print(keyword.kwlist) # kwlist contains all the keywords of Python
More on keywords
To check whether a given word is a python keyword or not, we use a built-in function iskeyword().
This function returns a boolean value, if the given word is keyword then it returns True as output
otherwise returns False.
Let us consider a few examples:
Program - 1:
import keyword # We have to import keyword module
print(keyword.iskeyword('and')) # Here 'and' is a keyword so it prints True as output
Output: True
Program - 2:
import keyword # We have to import keyword module
print(keyword.iskeyword('python')) # Here 'python' is not a keyword so it prints False as output
Output: False
Which of the following options are correct?
1. Python version 3.5 has 33 keywords.
2. true is a valid keyword in Python.
3. The keyword nonlocal does not exist in Python 2.
4. Interpreter raises an error when you try to use keyword as a name of an entity.
5. A programmer can easily modify the keywords.
A. All options are correct
B. 1,2,3 and 4 only
C. 3 and 4 only
D. 1,3 and 4 only
Which of the following options are correct?
1. Python version 3.5 has 33 keywords.
2. true is a valid keyword in Python.
3. The keyword nonlocal does not exist in Python 2.
4. Interpreter raises an error when you try to use keyword as a name of an entity.
5. A programmer can easily modify the keywords.
A. All options are correct
B. 1,2,3 and 4 only
C. 3 and 4 only
D. 1,3 and 4 only

More Related Content

Similar to UNIT1Lesson 2.pptx

Uniti classnotes
Uniti classnotesUniti classnotes
Uniti classnotesSowri Rajan
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.pptjaba kumar
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| FundamentalsMohd Sajjad
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiersNilimesh Halder
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of pythonBijuAugustian
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1Srinimf-Slides
 
python full notes data types string and tuple
python full notes data types string and tuplepython full notes data types string and tuple
python full notes data types string and tupleSukhpreetSingh519414
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHBhavsingh Maloth
 
Basic concepts of python
Basic concepts of pythonBasic concepts of python
Basic concepts of pythondeepalishinkar1
 
Python Fundamentals for the begginers in programming
Python Fundamentals for the begginers in programmingPython Fundamentals for the begginers in programming
Python Fundamentals for the begginers in programmingbsse20142018
 

Similar to UNIT1Lesson 2.pptx (20)

How To Tame Python
How To Tame PythonHow To Tame Python
How To Tame Python
 
Python Session - 2
Python Session - 2Python Session - 2
Python Session - 2
 
Python Data Types
Python Data TypesPython Data Types
Python Data Types
 
Uniti classnotes
Uniti classnotesUniti classnotes
Uniti classnotes
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Python programming
Python programmingPython programming
Python programming
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1
 
python full notes data types string and tuple
python full notes data types string and tuplepython full notes data types string and tuple
python full notes data types string and tuple
 
Python PPT.pptx
Python PPT.pptxPython PPT.pptx
Python PPT.pptx
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
 
Python Guide.pptx
Python Guide.pptxPython Guide.pptx
Python Guide.pptx
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Basic concepts of python
Basic concepts of pythonBasic concepts of python
Basic concepts of python
 
Python Fundamentals for the begginers in programming
Python Fundamentals for the begginers in programmingPython Fundamentals for the begginers in programming
Python Fundamentals for the begginers in programming
 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
 
INTERNSHIP REPORT.docx
 INTERNSHIP REPORT.docx INTERNSHIP REPORT.docx
INTERNSHIP REPORT.docx
 

More from CheriviralaNikhil

More from CheriviralaNikhil (6)

A323568347_29695_5_2024_Lecture0_INT232.ppt
A323568347_29695_5_2024_Lecture0_INT232.pptA323568347_29695_5_2024_Lecture0_INT232.ppt
A323568347_29695_5_2024_Lecture0_INT232.ppt
 
Introduction to OS.pdf
Introduction to OS.pdfIntroduction to OS.pdf
Introduction to OS.pdf
 
DPPM V.pdf
DPPM V.pdfDPPM V.pdf
DPPM V.pdf
 
Lecture1-2.ppt
Lecture1-2.pptLecture1-2.ppt
Lecture1-2.ppt
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
 
Data Models.pptx
Data Models.pptxData Models.pptx
Data Models.pptx
 

Recently uploaded

Guide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNGuide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNBruce Bennett
 
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)sonalinghatmal
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...ZurliaSoop
 
Personal Brand Exploration ppt.- Ronnie Jones
Personal Brand  Exploration ppt.- Ronnie JonesPersonal Brand  Exploration ppt.- Ronnie Jones
Personal Brand Exploration ppt.- Ronnie Jonesjonesyde302
 
Résumé (2 pager - 12 ft standard syntax)
Résumé (2 pager -  12 ft standard syntax)Résumé (2 pager -  12 ft standard syntax)
Résumé (2 pager - 12 ft standard syntax)Soham Mondal
 
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...amitlee9823
 
Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...only4webmaster01
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkSujalTamhane
 
Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...
Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...
Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...Pooja Nehwal
 
Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........deejay178
 
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...amitlee9823
 
➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men 🔝Mirzapur🔝 Escor...
➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men  🔝Mirzapur🔝   Escor...➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men  🔝Mirzapur🔝   Escor...
➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men 🔝Mirzapur🔝 Escor...amitlee9823
 
WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)Delhi Call girls
 
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...amitlee9823
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.GabrielaMiletti
 
Personal Brand Exploration - Fernando Negron
Personal Brand Exploration - Fernando NegronPersonal Brand Exploration - Fernando Negron
Personal Brand Exploration - Fernando Negronnegronf24
 
Resumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineResumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineBruce Bennett
 
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...amitlee9823
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfKen Fuller
 
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls DubaiDark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls Dubaikojalkojal131
 

Recently uploaded (20)

Guide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNGuide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWN
 
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
 
Personal Brand Exploration ppt.- Ronnie Jones
Personal Brand  Exploration ppt.- Ronnie JonesPersonal Brand  Exploration ppt.- Ronnie Jones
Personal Brand Exploration ppt.- Ronnie Jones
 
Résumé (2 pager - 12 ft standard syntax)
Résumé (2 pager -  12 ft standard syntax)Résumé (2 pager -  12 ft standard syntax)
Résumé (2 pager - 12 ft standard syntax)
 
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 9155563397 👗 Top Class Call Girl Service Ban...
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmk
 
Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...
Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...
Dombivli Call Girls, 9892124323, Kharghar Call Girls, chembur Call Girls, Vas...
 
Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........
 
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
 
➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men 🔝Mirzapur🔝 Escor...
➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men  🔝Mirzapur🔝   Escor...➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men  🔝Mirzapur🔝   Escor...
➥🔝 7737669865 🔝▻ Mirzapur Call-girls in Women Seeking Men 🔝Mirzapur🔝 Escor...
 
WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Salarpur Sector 81 ( Noida)
 
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 
Personal Brand Exploration - Fernando Negron
Personal Brand Exploration - Fernando NegronPersonal Brand Exploration - Fernando Negron
Personal Brand Exploration - Fernando Negron
 
Resumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineResumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying Online
 
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
 
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls DubaiDark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
 

UNIT1Lesson 2.pptx

  • 2. COMMENTS A computer program is a collection of instructions or statements. A Python program is usually composed of multiple statements. Each statement is composed of one or a combination of the following: 1.Comments 2.Whitespace characters 3.Tokens In a computer program, a comment is used to mark a section of code as non-executable. Comments are mainly used for two purposes: a) To mark a section of source code as non-executable, so that the Python interpreter ignores it. b) To provide remarks or an explanation on the working of the given section of code in plain English, so that a fellow programmer can read the comments and understand the code.
  • 3. Types of Comments with examples In Python, there are two types of comments: 1. Single-line comment : It starts with # (also known as the hash or pound character) and the content following # till the end of that line is a comment. 2. Docstring comment : Content enclosed between triple quotes, either ''' or """. Below code example demonstrates the usage of comments: Key points in relation to comments: 1. The # character must be specified at beginning of a comment line. 2. Comments do not nest. Meaning # has no special meaning inside a comment line which starts with #. 3. One cannot write comments inside string literals which are enclosed between single-quotes or double-quotes. The # character inside a string literal is treated as part of the string's content. 4. In a comment anything written after # in a particular line is ignored by the interpreter. Meaning it does not form part of the executable code in the program.
  • 4. Practice Question: 1. Make the following changes in the below code : Remove the comment on the line which prints "I am a Python Guru" Add a comment on the line which prints "Python is not cool"
  • 5. Python provides a way to specify documentation comments, called docstrings. A docstring is a string literal (plain text usually in English) provided in the source code to document what a particular segment of code does.  Python allows the use of both """triple-double-quotes""" or '''triple-single-quotes''' to create docstrings. However, the Python coding conventions specification recommends us to use """triple-double-quotes""" for consistency. The main purpose of docstrings in Python is to provide information on what a particular Python object does and not how it does According to the Python coding conventions, the docstring should always begin with a capital letter and end with a period (.) Example: """ This is a comment written in more than just one line """ print("Hello, World!") Note: docstrings inside modules, classes, functions, members, method definitions, etc. will be done later
  • 6. Identifier An identifier is a name used to identify a variable, function, class, module, or object. In Python, an identifier is like a noun in English. Identifier helps in differentiating one entity from the other. For example, name and age which speak of two different aspects are called identifiers. Python is a case-sensitive programming language. Meaning, Age and age are two different identifiers in Python. Rules: 1) Identifiers can be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore ( _ ). Examples: myClass, var_1, print_this_to_screen, _number are valid Python identifiers. 2) An identifier can start with an alphabet or an underscore (_), but not with a digit. Examples: 1_variable is invalid, but variable_1 is perfectly fine. 3) Keywords cannot be used as identifiers. (Keywords are reserved words in Python which have a special meaning). Examples: def, and, not, for, while, if, else etc. 4) Special symbols like !, @, #, $, % etc. are not allowed in identifiers. Only one special symbol underscore (_) is allowed. Examples: company#name, $name, email@id are invalid Python identifiers. 5) Identifiers can be of any length.
  • 7. Which of the following options are correct? 1. Identifiers are used for identifying entities in a program. 2. We can use any special character like @,#,$ as part of identifiers. 3. 1st_string is a valid identifier. 4. string_1 is valid identifier. 5. Identifiers can be of any length. A. All are Correct B. 1,2 and 3 only C. 1,4 and 5 only D. 1,3 and 4 only
  • 8. Which of the following options are correct? 1. Identifiers are used for identifying entities in a program. 2. We can use any special character like @,#,$ as part of identifiers. 3. 1st_string is a valid identifier. 4. string_1 is valid identifier. 5. Identifiers can be of any length. A. All are Correct B. 1,2 and 3 only C. 1,4 and 5 only D. 1,3 and 4 only
  • 9. Keywords Every programming language usually has a set of words know as keywords. These are reserved words with special meaning and purpose. They are used only for the intended purpose. Note : We cannot use a keyword as a variable name, function name or as any other identifier name. Python 2 has 32 keywords while Python 3.5 has 33 keywords. An extra keyword called nonlocal was added in Python 3.5. 2 more keywords were added in Python 3.7 making it to 35 Latest version is also having 35 keywords ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] Python provides a way to print the list of keywords in its current version. import keyword # This statement is used to import keyword module. print(keyword.kwlist) # kwlist contains all the keywords of Python
  • 10. More on keywords To check whether a given word is a python keyword or not, we use a built-in function iskeyword(). This function returns a boolean value, if the given word is keyword then it returns True as output otherwise returns False. Let us consider a few examples: Program - 1: import keyword # We have to import keyword module print(keyword.iskeyword('and')) # Here 'and' is a keyword so it prints True as output Output: True Program - 2: import keyword # We have to import keyword module print(keyword.iskeyword('python')) # Here 'python' is not a keyword so it prints False as output Output: False
  • 11. Which of the following options are correct? 1. Python version 3.5 has 33 keywords. 2. true is a valid keyword in Python. 3. The keyword nonlocal does not exist in Python 2. 4. Interpreter raises an error when you try to use keyword as a name of an entity. 5. A programmer can easily modify the keywords. A. All options are correct B. 1,2,3 and 4 only C. 3 and 4 only D. 1,3 and 4 only
  • 12. Which of the following options are correct? 1. Python version 3.5 has 33 keywords. 2. true is a valid keyword in Python. 3. The keyword nonlocal does not exist in Python 2. 4. Interpreter raises an error when you try to use keyword as a name of an entity. 5. A programmer can easily modify the keywords. A. All options are correct B. 1,2,3 and 4 only C. 3 and 4 only D. 1,3 and 4 only