0% found this document useful (0 votes)
1 views

8 - Python Data Types

Uploaded by

imujahid.2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

8 - Python Data Types

Uploaded by

imujahid.2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

1312 / 121 CCS-3

Introduction to Programming

Lecture 8, PYTHON – DATA TYPES

1
PYTHON – DATA TYPES
Lecture Goals
4. Built-in data types:
1. What is a Data Type in I. Numeric types,
python? II. bool data type (boolean data type),
III. None data type,
2. type(p) function
IV. Sequences in Python,
3. Different types of data types i. string data type,
ii. list data structure,
iii. tuple data structure,
iv. set data structure,
v. dictionary data structure,
vi. range data type,
5. User defined data types
2
Dr. Quadri Noorulhasan Naveed 2
1. What is a Data Type in python?
✓A data type represents the type of the data / values stored into a
variable or memory.

3
Dr. Quadri Noorulhasan Naveed 3
Data Type in python

4
Dr. Quadri Noorulhasan Naveed 4
Data Type in python example

5
Dr. Quadri Noorulhasan Naveed 5
2. type(p) function
✓type(p) is predefined function in python.
✓By using this we can check the data type of each variables.

6
Dr. Quadri Noorulhasan Naveed 6
3. Different types of data types

✓There are two type of data types.

➢ Built-in data types

➢ User defined data types

7
Dr. Quadri Noorulhasan Naveed 7
4. Built-in data types
✓The data types which are already existing in Python are called built-in
data types.

I. Numeric types IV. Sequence


ostr
oint
olist
ofloat
otuple
II. bool (boolean type) oset
III. None odict
orange
8
Dr. Quadri Noorulhasan Naveed 8
I. Numeric types
✓The numeric types represent numbers, these are divided into two types,
1. int
2. float

1. int data type

✓The int data type represents a number without decimal values.


✓In python there is no limit for int data type.
✓It can store very large values conveniently.

9
Dr. Quadri Noorulhasan Naveed 9
int data type example
Example 1: Example 2:

10
Dr. Quadri Noorulhasan Naveed 10
2. float data type
✓The float data type represents a number with decimal values.

11
Dr. Quadri Noorulhasan Naveed 11
II. bool data type (boolean data type)
✓bool data type represents boolean values in python.
✓bool data type having only two values those are,
oTrue
oFalse

Make a note

✓Python internally represents,

oTrue as 1
oFalse as 0
12
Dr. Quadri Noorulhasan Naveed 12
bool data type (boolean data type) example

13
Dr. Quadri Noorulhasan Naveed 13
III. None data type
✓None data type represents an object that does not contain any value.
✓If any object having no value, then we can assign that object with None data type.

Note
✓A function and method can
return None data type.
✓This point we will understand
more in function’s chapter.

14
Dr. Quadri Noorulhasan Naveed 14
IV. Sequences in Python
✓Sequence means an object.
Make a note
✓Sequence object can store a
group of values, ✓Regarding sequences like string, list,
tuple, set and dict we will discuss
i. string more in upcoming chapters
▪ Python String chapter
ii. list ▪ Python List Data Structure chapter
▪ Python Tuple Data Structure
iii.tuple chapter
▪ Python Set Data Structure chapter
iv.set ▪ Python Dictionary Data Structure
v. dict chapter

vi.range
15
Dr. Quadri Noorulhasan Naveed 15
IV. Sequences in Python
✓Sequence means an object.
✓Sequence object can store a group of values,
i. string
ii. list
iii.tuple
iv.set
v. dict
vi.range
16
Dr. Quadri Noorulhasan Naveed 16
i. string
✓A group of characters enclosed within single quotes or double quotes, or
triple quotes is called as string.

17
Dr. Quadri Noorulhasan Naveed 17
ii. list data structure
✓ We can create list data structure by using square brackets []
✓ list can store a group of values.

18
Dr. Quadri Noorulhasan Naveed 18
iii. tuple data structure
✓We can create tuple data structure by using parenthesis symbol ()
✓tuple can store a group of values.

19
Dr. Quadri Noorulhasan Naveed 19
iv. set data structure
✓We can create set data structure by using curly braces {}
✓set can store a group of values.

20
Dr. Quadri Noorulhasan Naveed 20
v. dictionary data structure
✓We can create dictionary data structure by using curly braces {}
✓Dictionary can store a group of values in the form of key value pair.

21
Dr. Quadri Noorulhasan Naveed 21
vi. range data type
✓range is a data type in python.
✓Generally, range means a group of values from starting to ending.
Creating range of values

✓We can create range of values by using range(p) predefined


function

1. range(p) function
✓As discussed, we can create range of values by using range(p)
function.
✓Here p should be integer, otherwise we will get error.
22
Dr. Quadri Noorulhasan Naveed 22
range data type example

Note:
✓If we provide range(5), then range object holds the values from 0 to 4
23
Dr. Quadri Noorulhasan Naveed 23
range(start, end) function
✓As discussed, we can create range of values by using range(start, end)
function.
✓Here start means starting value and end means till to end-1 value

Note:
✓If we provide range(1, 10), then range object holds the values from 1 to 9
24
Dr. Quadri Noorulhasan Naveed 24
Accessing range values by using for loop
✓We can access range values by using for loop.

25
Dr. Quadri Noorulhasan Naveed 25
5. User defined data types
✓ Data types which are created by programmer.

✓ The datatype which are created by the programmers


are called ‘user- defined’ data types, example is class,
module, array etc.

✓ This topic is mostly related to Object-oriented


programming.

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

Questions?
27

You might also like