1) Python Numbers
Number data type stores Numerical Values. These are of three different types:
a) Integer & Long
b) Float / floating point
Integer & Long Integer
Range of an integer in Python can be from -2147483648 to 2147483647, and long
integer has unlimited range subject to available memory.
Integers are the whole numbers consisting of + or – sign with decimal digits like 100000, -99,
0, 17. While writing a large integer value, don’t use commas to separate digits. Also, integers
should not have leading zeros.
Floating Point:
Numbers with fractions or decimal point are called floating point numbers.
A floating-point number will consist of sign (+,-) sequence of decimals digits and a dot such
as 0.0, -21.9, 0.98333328, 15.2963. These numbers can also be used to represent a
number in engineering/ scientific notation.
-2.0 x 105
will be represented as -2.0e5
2.0X10-5 will be 2.0E-5
3) Sequence
A sequence is an ordered collection of items, indexed by positive integers. It is a
combination of mutable and non-mutable data types. Three types of sequence data
type available in Python are:
a) Strings
b) Lists
c) Tuples
String
String is an ordered sequence of letters/characters. They are enclosed in single quotes
(‘ ‘) or double (“ “). The quotes are not part of string. They only tell the computer where the
string constant begins and ends. They can have any character or sign, including space in
them.
Lists
List is also a sequence of values of any type. Values in the list are called elements / items.
These are indexed/ordered. List is enclosed in square brackets.
Example:
40
dob = [19,"January",1990]
Tuples:
Tuples are a sequence of values of any type, and are indexed by integers. They are
immutable. Tuples are enclosed in ().
Example:
t = (5,'program',2.5)
4) Set
Sets are used to store multiple items in a single variable.
Set is one of 4 built-in data types in Python used to store collections of data,
the other 3 are List, Tuple, and Dictionary, all with different qualities and
usage.
A set is a collection which is unordered, unchangeable*, and unindexed.
Set is an unordered collection of values, of any type, with no duplicate entry.
Example:
>>> a = {1,2,2,3,3,3}
>>> a
{1,2,3}
thisset = {"apple", "banana", "cherry"}
print(thisset)
5) Mapping
This data type is unordered. Dictionaries fall under Mappings.
Dictionaries
Dictionary is an unordered collection of key-value pairs. It is generally used when we have a
huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to
retrieve the value.
In Python, dictionaries are defined within braces {} with each item being a pair in the
form key: value. Key and value can be of any type.
Example
>>> d = {1:'Ajay','key':2}
>>> type(d)
<class 'dict'>
Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is ordered*, changeable and do not allow duplicates.
Dictionaries are written with curly brackets, and have keys and values:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)