Python Notes
Python Notes
Number data type stores Numerical Values. These are of three different types:
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
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
-2.0 x 105
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
a) Strings
b) Lists
c) Tuples
String
(‘ ‘) 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.
Example:
40
dob = [19,"January",1990]
Tuples:
Tuples are a sequence of values of any type, and are indexed by integers. They are
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.
Example:
>>> a = {1,2,2,3,3,3}
>>> a
{1,2,3}
thisset = {"apple", "banana", "cherry"}
print(thisset)
5) Mapping
Dictionaries
huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to
In Python, dictionaries are defined within braces {} with each item being a pair in the
Example
>>> d = {1:'Ajay','key':2}
>>> type(d)
<class 'dict'>
Dictionaries are written with curly brackets, and have keys and values:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)