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

Python Programming 1 Data Types

Uploaded by

Surya Surya
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)
11 views4 pages

Python Programming 1 Data Types

Uploaded by

Surya Surya
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

CSA0810-PYTHON PROGRAMMING

DATA TYPES:

1. Write a Python program to find the union of two sets


2. Write a Python program to sort a list in descending order.
3. Write a Python program to remove all occurrences of a specified element from a list.
4. Write a Python program to find the intersection of two sets.
5. Write a Python program to find the length of a string.
6. Write a Python program to concatenate two strings.
7. Write a Python program to convert a tuple to a list.
8. Write a Python program to convert a list to a tuple.
9. Write a Python program to convert a string to an integer.
10. Write a Python program to convert a string to a float.
1. Write a Python program to find the union of two sets

Program
set1 = {1, 2, 3}
set2 = {4, 5, 6}
unionSet = set1 | set2
print(f"Set1 is {set1}")
print(f"Set1 is {set2}")
print(f" Union set is {unionSet}")
Output
Set1 is {1, 2, 3}
Set1 is {4, 5, 6}
Union set is {1, 2, 3, 4, 5, 6}

2. Write a Python program to sort a list in descending order.


Program:
list1 = [22, 34, 21, 56, 71, 44]
print(f"Given List:\n {list1}")
list1.sort()
print(f"Descending Order:\n {list1[::-1]}")
Output:
Given List:
[22, 34, 21, 56, 71, 44]
Descending Order:
[71, 56, 44, 34, 22, 21]

3. Write a Python program to remove all occurrences of a specified element from a list.
Program
inList = [22, 34, 21, 22, 56, 71, 44, 22]
print(f"Given List:\n {inList}")
rme = 22
outList = [x for x in inList if x!=rme]
print(f"Remove Element:{rme}")
print(f"Output List:\n {outList}")
Output:
Given List:
[22, 34, 21, 22, 56, 71, 44, 22]
Remove Element:22
Output List:
[34, 21, 56, 71, 44]

4. Write a Python program to find the intersection of two sets.


Program:
inList1 = {1, 2, 3, 4, 5, 6}
inList2 = {4, 5, 6, 7, 8, 9}
print(f"Given List 1:\n {inList1}")
print(f"Given List 2:\n {inList2}")
outList = inList1.intersection(inList2)
print(f"Intersection of two Sets:\n {inList2}")
Output:
Given List 1:
{1, 2, 3, 4, 5, 6}
Given List 2:
{4, 5, 6, 7, 8, 9}
Intersection of two Sets:
{4, 5, 6, 7, 8, 9}

5. Write a Python program to find the length of a string.


Program
inString = "SIMATS"
print(f"Given String : {inString}")
print(f"Length of String : {len(inString)}")
Output:
Given String : SIMATS
Length of String : 6

6. Write a Python program to concatenate two strings.


Program:
inString1 = "SIMATS"
inString2 = "SSE"
print(f"Given String 1 : {inString1}")
print(f"Given String 2 : {inString2}")
outString = inString1 + inString2
print(f"Concatenate Two String : {outString}")
Output:
Given String 1 : SIMATS
Given String 2 : SSE
Concatenate Two String : SIMATSSSE

7. Write a Python program to convert a tuple to a list.


Program:
inTuple = (1, 2, 3)
print(f"Input Type : {type(inTuple)}")
print(f"Input Tuple : {inTuple}")
outList = list(inTuple)
print(f"Output Type : {type(outList)}")
print(f"Output List : {outList}")
Output:
Input Type : <class 'tuple'>
Input Tuple : (1, 2, 3)
Output Type : <class 'list'>
Output List : [1, 2, 3]
8. Write a Python program to convert a list to a tuple.
Program:
inList = [1, 2, 3]
print(f"Input Type : {type(inList)}")
print(f"Input List : {inList}")
outTuple = tuple(inList)
print(f"Output Type : {type(outTuple)}")
print(f"Output Tuple : {outTuple}")
Output:
Input Type : <class 'list'>
Input List : [1, 2, 3]
Output Type : <class 'tuple'>
Output Tuple : (1, 2, 3)

9. Write a Python program to convert a string to an integer.


Program :
inString = "123456"
print(f"Input Type : {type(inString)}")
print(f"Input : {inString}")
outInt = int(inString)
print(f"Output Type : {type(outInt)}")
print(f"Output : {outInt}")
Output:
Input Type : <class 'str'>
Input : 123456
Output Type : <class 'int'>
Output : 123456

10. Write a Python program to convert a string to a float.


Program:

inString = "123.123456"
print(f"Input Type : {type(inString)}")
print(f"Input : {inString}")
outFlot = float(inString)
print(f"Output Type : {type(outFlot)}")
print(f"Output : {outFlot}")
Output:
Input Type : <class 'str'>
Input : 123.123456
Output Type : <class 'float'>
Output : 123.123456

You might also like