0% found this document useful (0 votes)
5 views15 pages

ب ٣

This lecture covers Python naming conventions, focusing on identifiers, their rules, and the importance of following these conventions for code clarity. It outlines five key rules for creating valid identifiers and discusses the use of comments in Python programming, including single and multi-line comments. The lecture emphasizes that adhering to these conventions makes code easier to read, understand, and debug.

Uploaded by

rbd45585h5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

ب ٣

This lecture covers Python naming conventions, focusing on identifiers, their rules, and the importance of following these conventions for code clarity. It outlines five key rules for creating valid identifiers and discusses the use of comments in Python programming, including single and multi-line comments. The lecture emphasizes that adhering to these conventions makes code easier to read, understand, and debug.

Uploaded by

rbd45585h5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1312 / 121 CCS-3

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?

Python creator made some suggestions to the programmers


regarding how to write identifiers in a program.
While writing the program if we follow the naming conventions then
the written code is,

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,

oAlphabets, either upper case or lower case


oNumbers from 0 to 9
oUnderscore symbol (_)

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

1.Single line comments

2.Multi line 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

You might also like