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

exp 1 & 2

The document provides an introduction to data types in Python, including lists, tuples, sets, and dictionaries, along with their characteristics and usage. It explains various operations that can be performed on these data types, such as sorting and indexing for lists, and set operations like union and intersection. Additionally, it covers dictionary operations including insertion, deletion, and value retrieval.

Uploaded by

Kartik Bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

exp 1 & 2

The document provides an introduction to data types in Python, including lists, tuples, sets, and dictionaries, along with their characteristics and usage. It explains various operations that can be performed on these data types, such as sorting and indexing for lists, and set operations like union and intersection. Additionally, it covers dictionary operations including insertion, deletion, and value retrieval.

Uploaded by

Kartik Bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Program 1

AIM: Introduction to Data Types in Python.

THEORY: Python is a popular programming language that was created by Guido van Rossum and released
in 1991. Python is used for web development, system scripting, software development, and mathematics.
it can work on different platforms and has a simple syntax similar to the English language. Python runs on
an interpreter system. different kinds of data types are available in python.
Data types are the classification of data items. They represent the kind of value that tells what operations
can be performed on a particular data. The different types of collection data types in the python
programming language are list, tuple, set, and dictionary.

1. List - it is a collection of items that are ordered and changeable. The list is used to store multiple
items in a single variable. They are created using square brackets. we can store duplicate members
in it.
2. Tuple - It is a collection of items that are ordered and unchangeable. they are used to store
multiple items in a single variable. duplicate items can be used in a tuple. The elements of a tuple
cannot be changed. They are enclosed in parentheses (). We cannot use the sort function and
assign a new value to index in a tuple, if we do so then it will create an error.
3. Sets - It is a collection of items that are unordered and unindexed. In this, we cannot insert
duplicate members. It is used to store multiple items in a single variable. elements are written in
curly brackets.
4. Dictionary – It is a collection of items that are unordered and changeable. It does not allow
duplicate members. They store data values in key: value pairs. They are written in curly brackets. In
this, each key holds a specific value.
Program 2
AIM: Implementation of various operations on data types in Python.

THEORY:
1. List - We can perform different functions on the list:
a. Len () function – it is used to find out the length of the list or to determine that how many
items are present in a list
b. Sort () function – this is used to sort all the items present in a list.
c. Index [] – It is used to access an item in a list using its index number. index number starts from
0
d. Negative indexing [] – we can access the items from the end by using negative indexing. It
means indexing beginning from the end, -1 refers to the last item, -2 refers to the second-last
item.
e. Slicing – It enables us to access different parts of the list.

2. Tuple - We can use the same functions which we are using in the list except for sort and
assigning index a new value, if we try to change the value in tuple then it will give an error.
3. Sets – different operations that are being performed on sets are :
a. Intersection operation: it gives an intersection of given sets. The & operator is used in this
operation. it gives common elements to both sets.
b. Union operation: the union of two sets is the set of all elements from both sets. We can get
the union of two sets by using the union() method or | operator.
c. Difference operation: it gives a set of all the elements that are only present in set1 and not
in set2. we can create the difference of two sets by using – operator or the difference()
method.
d. Symmetric difference operation: this gives a set of elements that are either in set1 or in
set2 but not in both. We can use the ^ operator or symmetric_difference() method for
performing this operation.

4. Dictionary- The operations which can be performed on a dictionary are:


a. Printing value from a given key
b. Insertion – we can insert a new key-value pair in an existing dictionary
c. Deletion – we can remove a key-value pair from a dictionary using the del function
d. Replace – we can change the value for a given key
36 labelencoder_Y = Label Encoder ()
37 Y = labelencoder_Y . fit_transform ( Y)
38 print ( Y)
39
40 # Splitting the data into training and test set
41 X_train , X_test , Y_train , Y_test = train_test_split (X, Y, test_size = 0.15 , random_state = 0)
42
43 # Feature Scaling
44 st_X = Standard Scaler ()
45 X_train = st_X . fit_transform ( X_train )
46 print ( X_train )
47
48 X_test = st_X . transform ( X_test )

You might also like