ب ٣
ب ٣
Introduction to Programming
Lecture 3,
PYTHON – NAMING CONVENTIONS
1
PYTHON – NAMING CONVENTIONS
Lecture Goals
1. What is Identifier?
2. Why should we follow naming conventions?
3. 5 Rules to follow for identifiers in Python
4. Comments in Python program
5. Purpose of comments:
1. Singe line comments
2. Multi line comments
2
Dr. Quadri Noorulhasan Naveed 2
1. WHAT IS IDENTIFIER?
A name in a python program is called identifier.
This name can be,
o Package name
o Module name
o Variable name
o Function name
o Class name
o Method name
3
Dr. Quadri Noorulhasan Naveed 3
2. WHY SHOULD WE FOLLOW NAMING CONVENTIONS?
o Easy to understand.
o Easy to read.
o Easy to debug.
4
Dr. Quadri Noorulhasan Naveed 4
3. 5 POINTS TO FOLLOW FOR IDENTIFIERS IN PYTHON
# Point 1
While writing an identifier we can use,
If we are using any other symbol, then we will get syntax error.
5
Dr. Quadri Noorulhasan Naveed 5
Example
6
Dr. Quadri Noorulhasan Naveed 6
# Point 2
We can write an identifier with number, but identifier should not start with digit.
7
Dr. Quadri Noorulhasan Naveed 7
# Point 3
Identifiers are case sensitive.
8
Dr. Quadri Noorulhasan Naveed 8
# Point 4
We cannot use keywords as identifiers.
9
Dr. Quadri Noorulhasan Naveed 9
# Point 5
Spaces are not allowed in between the identifier.
10
Dr. Quadri Noorulhasan Naveed 10
Examples
435student # invalid
Student564 # valid
Student565info # valid
$tudent # invalid
_student_info # valid
class # invalid
def # invalid
11
Dr. Quadri Noorulhasan Naveed 11
5. COMMENTS IN PYTHON PROGRAM
There are two types of comments
Purpose of comments
Comments are useful to describe about the code in an easy way.
Python ignores comments while running the program
12
Dr. Quadri Noorulhasan Naveed 12
5. COMMENTS IN PYTHON PROGRAM (Cont.)
1.Singe line comments
By using single line comment, we can comment only a single line.
To comment single line, we need to use hash symbol #
13
Dr. Quadri Noorulhasan Naveed 13
5. COMMENTS IN PYTHON PROGRAM (Cont.)
2.Multi line comments
By using multi line comment we can comment multiple lines.
To comment multiple lines, we need to use triple double quotes symbol.
14
Dr. Quadri Noorulhasan Naveed 14
1312 / 121 CCS-3
Introduction to Programming
Questions?
15