0% found this document useful (0 votes)
169 views

Assignment 2 Data Types

This document discusses various built-in data types in Python including numeric, sequence, boolean, set, and dictionary data types. Numeric data types include integers, floats, and complex numbers. Sequence data types include strings, lists, and tuples. Strings are arrays of characters, lists are ordered collections that can hold different data types, and tuples are ordered and immutable. Boolean data type represents true and false values. Set is an unordered collection with no duplicate elements. Dictionary is an unordered collection of key-value pairs that provides optimized lookup.

Uploaded by

Sajjad Ali SagEr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

Assignment 2 Data Types

This document discusses various built-in data types in Python including numeric, sequence, boolean, set, and dictionary data types. Numeric data types include integers, floats, and complex numbers. Sequence data types include strings, lists, and tuples. Strings are arrays of characters, lists are ordered collections that can hold different data types, and tuples are ordered and immutable. Boolean data type represents true and false values. Set is an unordered collection with no duplicate elements. Dictionary is an unordered collection of key-value pairs that provides optimized lookup.

Uploaded by

Sajjad Ali SagEr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lahore Garrison University (LGU)

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.

 Built in Data Type:


1. Sequence
2. Numeric
3. Boolean
4. Dictionary
5. Set

 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

print("Type of c: ", type(c))

 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.

These are the type of sequence


 String
 List
 Tuple
String
In Python, Strings are arrays of bytes representing Unicode characters. A string is
a collection of one or more characters put in a single quote, double-quote or
triple quote. In python there is no character data type, a character is a string of
length one. It is represented by str class

For example we create a string


„‟ Hello how are you”
We print the string

Print(“This is my first program”)


Note: string is also used in singal quotes and triple quotes
 list
Lists are just like the arrays, declared in other languages which is a ordered
collection of data. It is very flexible as the items in a list do not need to be of the
same type

For example create a list.


List are creating by the square bracket [ ].

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)

Creating a tuple with the use of built in function.


Tuple1 = tuple('Geeks')
print("\nTuple with the use of function: ")
print(Tuple1)

 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)

Creating a Dictionary with Mixed keys


Dict = {'Name': 'Geeks', 1: [1, 2, 3, 4]}
print("Dictionary with the use of Mixed Keys: ")
print(Dict)

You might also like