CHAPTER 3 – DATA TYPES
Integer
Python Data Types Float
Number Complex
Boolean
Dictionary
Set
Sequence Type List
String
Tuple
NOTE :- The fundamental data type in python are :- Int, float, complex, str, bool
1. Numeric Data type
Numeric data type represent numbers
Numeric data type contain int, float and complex data type
Int :- Int data type contain integer values e.g. – 10, 20, 999, -120, -3
Float :- Float data type contain floating point value e.g. – 10.0, 5.0, -45.0
Complex :- Complex data type represent values in the form of real and imaginary part
e.g. – 10+5i
2. Sequence data type
String :- String data type is a sequence of characters represented in quotation
marks. We can represent single line and multi-line strings using single quotes and
double quotes. E.g. - ‘Python’ “Python is a
High level programming language’’
We can use triple quotes to represent single and double represent in a string
e.g. - ‘’’Python is a ‘high level programming language ‘’’
List :- If we want to represent a group of values as a single entity where insertion
order is preserved and duplicates are allowed then we go for list
Duplicates are allowed
Insertion order is preserved
Heterogeneous elements are allowed
Growable in nature
List is represented within square brackets
E.g. – [10, 20, ‘python’, ‘30’, True]
Tuple :- Tuple is exactly same as list but tuple is not mutable (i.e. immutable) like list
Basically tuple is read only version of list
E.g. – (10, 20, ‘python’, ‘30’, True)
Set :- If we want to represent a group of values as a single entity where insertion
order is not important and duplicates are not allowed then we use set
Insertion order is not preserved
Duplicates are not allowed
Heterogeneous elements are allowed
Growable in nature
Indexing concept is not applicable
Mutable in nature
Represented within parenthesis
E.g. - {0,10, ‘Python’, 99}
Dictionary :- If we want to represent a group of values in key value manner then we
go for dict data type. In dict data type duplicates keys are not allowed but values
can be duplicated. If we try to use duplicate key then old value of key will be
replaced by the new duplicated key value. Dict data type is mutable and order is not
preserved. Represented using curly braces {}
Bool :- used to represent Boolean values, only two values are allowed True, False
Range :- range data type represent a sequence of numbers. The elements present in
a range data type are not modifiable i.e. immutable. We can access values in range
data type using index.
e.g. – range(10) -> generate value from 0 to 9
range (10,20) -> generate value from 10 to 19
range (10,20,2) -> 2 represent increment value, we can put any value in place
2, it generate sequence as 10, 12, 14, 16, 18