Module 2 Lecture 3 Data Types
Module 2 Lecture 3 Data Types
(ITFC0101)
Lecture 3
Variable
In C, Java or some other programming languages, a variable is an identifier or
a name, connected to memory location.
a = 30
10 b = 10 c = 20
a b c
10
30 10 20
12114 12115 12117
y=a
y
30
12678
Variable
In Python, a variable is considered as tag that is tied to some value. Python
considers value as objects.
a = 10 b = 10 a = 20
a b a
10 10 20
12114 12115 12117
y=a
y
20
12678
Variable
In Python, a variable is considered as tag that is tied to some value. Python
considers value as objects.
a = 10 a = 20
a a
10 20
12114 12115
• Except underscore ( _ ) no other special symbol are allowed in the middle of the variable declaration
• A variable is written with a combination of letters, numbers and special characters _ (underscore)
• No Reserved keyword
Examples
Do Don’t
• A • and
• 15name
• a
• $city
• name
• Full$Name
• name15
• Full Name
• _city
• Full_name
• FullName
DataType
Datatype represents the type of data stored into a variable or memory.
Type of Data type :-
• Built-in Data type
• User Defined Data type
Data Types
Following are standard or built-in data types in
Python:
● Numeric
● Sequence Type
● Boolean
● Set
● Dictionary
None
Numeric Data Type
Represents the data that has a numeric value
● Integers – Value is represented by int class
>>> type(17)
<class 'int’>
>>> type(3.2)
<class 'float’>
Numeric Data Type
Represents the data that has a numeric value
● Float – Value is represented by float class
667575676787877897878.76)
● Python doesn’t care whether you use single or double quotes or the three-of-a-kind quotes to surround
strings
● Once it has parsed the text of your program or command
● 2D List
List Data Types
Multi-dimensional List
● 3D List
List Data Types
List with Duplicate elements
● List may have duplicate items
List Data Types
List with mixed type values (heterogeneous data elements)
● List supports heterogeneous data items
List Data Types
Accessing list with negative index
● In Python, negative sequence indexes represent positions from the end
● Negative indexing means beginning from the end, -1 refers to the last item, -2 refers to the second-last
item, etc.
● Offset List[len(List)-2] == List[-2]
● len(list): Number of elements in list
List Data Types
len() function in multidimensional list
Tuple Data Types
[1] 20 [-4] 20
data [2] -50 data [-3] -50
[3] 21.3 [-2] 21.3
[4] Python [-1] Python
Range – Range used to generate a sequence of numbers.
● Data type with one of the two built-in values: True or False
● Non-Boolean objects can be evaluated in a Boolean context as well
True + True = 2
True – False = 1
None data type
•The None keyword in Python is a data type and an object of the NoneType class.
None datatype represents an object that doesn’t contain any value.
• Identifier may contain letters and digits, but cannot begin with a digit.