7 - Python - Variables
7 - Python - Variables
Introduction to Programming
1
PYTHON – VARIABLES
Lecture Goals
1. Variable
2. Purpose of the variable
3. Naming convention to a variable
4. Creating a variable with examples
5. Creating multiple variables in single line with examples
6. Single value for multiple variables with example
7. Variable re-initialization with example
2
Dr. Quadri Noorulhasan Naveed 2
1. VARIABLE
✓Variable is a reserved memory location to store values OR
3
Dr. Quadri Noorulhasan Naveed 3
2. Purpose of the Variable
✓The purpose of variable is to represent the data
✓Data means a collection of facts
✓Facts can be,
o Alphabets.
o Numbers.
o Alphanumeric
o Symbols
4
Dr. Quadri Noorulhasan Naveed 4
3. Naming convention to a Variable
✓ Identifier or Variable (name) should be written as :
5
Dr. Quadri Noorulhasan Naveed 5
Identifier or Variable (name)
✓Valid Identifier or Variable (name)
6
Dr. Quadri Noorulhasan Naveed 6
Identifier or Variable (name)
✓Valid Identifier or Variable (name)
7
Dr. Quadri Noorulhasan Naveed 7
Identifier or Variable (name)
✓Valid Identifier or Variable (name)
8
Dr. Quadri Noorulhasan Naveed 8
4. Creating a Variable
✓We need to follow below syntax to create a variable.
Syntax
name_of_the_variable = value
Example
9
Dr. Quadri Noorulhasan Naveed 9
Assignment operator in creating a variable
10
Dr. Quadri Noorulhasan Naveed 10
Python program for creating Variable
(Run and reconfirm the output)
11
Dr. Quadri Noorulhasan Naveed 11
Python program for creating Variable
(Run and reconfirm the output)
12
Dr. Quadri Noorulhasan Naveed 12
Python program for creating Variable
(Run and reconfirm the output)
13
Dr. Quadri Noorulhasan Naveed 13
Python program for creating Variable
(Run and reconfirm the output)
14
Dr. Quadri Noorulhasan Naveed 14
Important note
15
Dr. Quadri Noorulhasan Naveed 15
5. Creating multiple Variables in single line
✓We can create multiple variables in single line
✓# Rule
oThere should be same number on the left and right-hand sides.
Otherwise, we will get error.
16
Dr. Quadri Noorulhasan Naveed 16
6. Single value for multiple Variables
✓We can assign a single value to multiple variables simultaneously.
17
Dr. Quadri Noorulhasan Naveed 17
7. Variable re-initialization
✓Based on requirement we
can re-initialize existing
variable value.
Example:
18
Dr. Quadri Noorulhasan Naveed 18
1312 / 121 CCS-3
Introduction to Programming
Questions?
19