0% found this document useful (0 votes)
5 views4 pages

EXPT02

The document outlines an experiment for a UG program in Electronics and Computer Science focusing on data structures in Python, including strings, lists, tuples, dictionaries, and sets. It provides specific coding tasks such as counting occurrences in a list and performing operations on a set, along with theoretical explanations of various data types. The document also emphasizes the properties and methods associated with these data structures.

Uploaded by

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

EXPT02

The document outlines an experiment for a UG program in Electronics and Computer Science focusing on data structures in Python, including strings, lists, tuples, dictionaries, and sets. It provides specific coding tasks such as counting occurrences in a list and performing operations on a set, along with theoretical explanations of various data types. The document also emphasizes the properties and methods associated with these data structures.

Uploaded by

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

UG Program in Electronics and Computer Science

Academic Year: 2024-2025

Experiment No. 2

Aim: Study of Strings, Lists, Tuples, Dictionaries, Sets, Accessing Elements, Properties,
Operations and methods on these data structures.

Problem Statement:

1. Write a Python code to count occurrences of an element in a list


2. Write a program to carry out the following operations on the given set
s = {10, 2, -3, 4, 5, 88}
a) Number of items in set s
b) Maximum element in set s
c) Minimum element in set s
d) Sum of all elements in set s
e) Obtain a new sorted set from s, set remaining unchanged
f) Report whether is 100 an element of set s
g) Report whether -3 is not an element of set s
3. Write a Python code to demonstrate student information Student Name Marks (5 Students)

Theory:
1. Explain various Data Types in Python.

Various Data Types in Python are as follows:

String: String is sequence of Unicode characters. We can use single quotes or double quotes to
represent strings. Multi-line strings can be denoted using triple quotes, ''' or """

s = "This is a string”

Slicing operator [ ] can be used with string. Strings are immutable


List: List is an ordered sequence of items. It is one of the most used data type in Python and is very
flexible. All the items in a list do not need to be of the same type.

Declaring a list is pretty straight forward. Items separated by commas are enclosed within brackets

[ ].

>>> a = [1, 2.2, 'python']

We can use the slicing operator [ ] to extract an item or a range of items from a list. Index starts form
0 in Python

Lists are mutable, meaning, value of elements of a list can be altered.


UG Program in Electronics and Computer Science
Academic Year: 2024-2025

Tuple: Tuple is an ordered sequence of items same as list. The only difference is that tuples are
immutable. Tuples once created cannot be modified.

Tuples are used to write-protect data and are usually faster than list as it cannot change dynamically.

It is defined within parentheses () where items are separated by commas.

>>> t = (5,'program', 1+3j)

We can use the slicing operator [] to extract items but we cannot change its value.

Set: Set is an unordered collection of unique items. Set is defined by values separated by comma
inside braces {}. Items in a set are not ordered.

a = {5,2,3,1,4}

print ("a = ", a)

print(type(a))

We can perform set operations like union, intersection on two sets. Set have unique values. They
eliminate duplicates.
Since, set are unordered collection, indexing has no meaning. Hence the slicing operator [] does not
work.

Dictionary: 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. d = {1:'value','key':2}

type(d) #<class 'dict'> print("d[1] = ", d[1]) print("d['key'] = ", d['key'])

We use key to retrieve the respective value. But not the other way around.
UG Program in Electronics and Computer Science
Academic Year: 2024-2025

Program
UG Program in Electronics and Computer Science
Academic Year: 2024-2025
Output

Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

You might also like