[go: up one dir, main page]

0% found this document useful (0 votes)
2 views19 pages

7 - Python - Variables

Uploaded by

imujahid.2004
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)
2 views19 pages

7 - Python - Variables

Uploaded by

imujahid.2004
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/ 19

1312 / 121 CCS-3

Introduction to Programming

Lecture 7, PYTHON – VARIABLES

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

✓Python having dynamic data type nature.


✓It means, while creating variable we no need to
provide the data type explicitly in python.
✓Regarding data type we will learn in Data type chapter.

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.

✓In variable re-initialization


old values will be replaced
with new values.

Example:

18
Dr. Quadri Noorulhasan Naveed 18
1312 / 121 CCS-3
Introduction to Programming

Questions?
19

You might also like