Assignment 2 Data Types
Assignment 2 Data Types
Assignment#1
Course Title: Programing Fundamental
Submitted to:
Prof. Khizra Hanif
Dept of: SE
Submitted by:
Sajjad Ali
Roll no: 049
Dept of: SE
Data type use in python
Data types are the classification of data items. It represents the kind of value
that tells what operations can be performed on a particular data.
Numeric
Integers:
In python this value is represent by the int class. It contain positive or negative
whole number (without fraction or decimal)
For example:
a=5
print ("Type of a: ", type(a))
Float:
This value is represented by the float class. It is specified by the
decimal point. It is real number with floating point representation.
For example
b = 5.0
print("Type of b: ", type(b))
Complex numbers:
Complex number represented by a complex class.it is specified a real part
and Imaginary part .
For example
-5+6j
c = 2 + 4j
Sequence Type:
In python sequence is the ordered collection of similar or different data types.
Sequences allows to store multiple values in an organized and efficient fashion.
List =[ ]
Print(“empty list”)
Print(list)
Tuple
In Python, tuples are created by placing a sequence of values separated by
‘comma’ with or without the use of parentheses for grouping of the data
sequence. Tuples can contain any number of elements and of any datatype (like
strings, integers, list, etc.).
Note: Tuples can also be created with a single element, but it is a bit
tricky. Having one element in the parentheses is not sufficient, there must
be a trailing „comma‟ to make it a tuple.
For example:
Tuple = ( )
Print(“Empty Tuple”)
Print(Tuple)
Boolean
Data type with one of the two built-in values, True or False. Boolean objects that
are equal to True are truthy (true), and those equal to False are falsy (false). But
non-Boolean objects can be evaluated in Boolean context as well and
determined to be true or false. It is denoted by the class bool.
Note – True and False with capital „T‟ and „F‟ are valid booleans
otherwise python will throw an error.
For example:
Print( type(True))
Print(type(False))
Set:
In Python, Set is an unordered collection of data type that is iterable, mutable
and has no duplicate elements. The order of elements in a set is undefined
though it may consist of various elements.
For example:
set1 = set()
Print(empty set)
Print(set1)
Dictionary:
Dictionarary in Python is an unordered collection of data values, used to store
data values like a map, which unlike other Data Types that hold only single value
as an element, Dictionary holds key:value pair. Key-value is provided in the
dictionary to make it more optimized. Each key-value pair in a Dictionary is
separated by a colon :, whereas each key is separated by a ‘comma’.
For example:
Dict = {}
print("Empty Dictionary: ")
print(Dict)