0% found this document useful (0 votes)
192 views36 pages

Essential Software: Dr. Muhammad Yousuf Tufail

This document appears to be a lecture on types of variables and lists in Python. It discusses integer, float, string, and Boolean variable types through an example. It then introduces lists as a way to store related data, like the heights of family members paired with their names. List entries can be accessed by index and printed. The document provides examples of creating and accessing a list of family member heights and names.

Uploaded by

Saadat Shaikh
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)
192 views36 pages

Essential Software: Dr. Muhammad Yousuf Tufail

This document appears to be a lecture on types of variables and lists in Python. It discusses integer, float, string, and Boolean variable types through an example. It then introduces lists as a way to store related data, like the heights of family members paired with their names. List entries can be accessed by index and printed. The document provides examples of creating and accessing a list of family member heights and names.

Uploaded by

Saadat Shaikh
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/ 36

Essential Software

Dr. Muhammad Yousuf Tufail

Department of Mathematics
Institute of Business Administration.
‡ Yousuf Tufail ¯ Yousuf Tufail
[email protected]

Lecture 3

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 1/5


Types of variable

Example (1)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution
a=2

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution
a=2
b=2.34

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution
a=2
b=2.34
c=‘I am string’

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Example (1)
What are the types of the following variable.
a=2, b=2.34, c=‘I am string’, d=True

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 2/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)
float

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)
float
type(c)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)
float
type(c)
string

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)
float
type(c)
string
type(d)

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)
float
type(c)
string
type(d)
bool

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5


Types of variable

Solution
a=2
b=2.34
c=‘I am string’ (It will be green in color)
d=True (It will be blue in color)
type(a)
int
type(b)
float
type(c)
string
type(d)
bool
Note: Strings are always written in ‘ ‘ or ” ”
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 3/5
Lists

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80
It looks quite inconvenient way of representation.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80
It looks quite inconvenient way of representation.
Python provides a better way to represent such data in the form of list as
explained below:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80
It looks quite inconvenient way of representation.
Python provides a better way to represent such data in the form of list as
explained below:
fam heights=[1.64,1.42,1.56,1.80]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80
It looks quite inconvenient way of representation.
Python provides a better way to represent such data in the form of list as
explained below:
fam heights=[1.64,1.42,1.56,1.80]
Above representation is better than previous.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80
It looks quite inconvenient way of representation.
Python provides a better way to represent such data in the form of list as
explained below:
fam heights=[1.64,1.42,1.56,1.80]
Above representation is better than previous.
But (still) we do not know the people corresponding to each height.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

Height of a family members:


height 1 = 1.64
height 2 = 1.42
height 3 = 1.56
height 4 = 1.80
It looks quite inconvenient way of representation.
Python provides a better way to represent such data in the form of list as
explained below:
fam heights=[1.64,1.42,1.56,1.80]
Above representation is better than previous.
But (still) we do not know the people corresponding to each height.
fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 4/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42
print(fam heights[2],fam heights[3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42
print(fam heights[2],fam heights[3])
Hazel 1.42

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42
print(fam heights[2],fam heights[3])
Hazel 1.42

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 5/5

You might also like