Friday, January 27, 2017

List and Tuple Datatype in Python

Tags

List and Tuple Both are datatypes in Python .These are similar to each other and used to store data of different types.But the only difference in list and tuple is that we can edit data in list but we can not edit data in tuple


For Example:

List =['76','23','25','85']

Tuple=('75','6','7')


Question:
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
Suppose the following input is supplied to the program:
34,67,55,33,12,98
Then, the output should be:
['34', '67', '55', '33', '12', '98']
('34', '67', '55', '33', '12', '98')



Code::

var=input("Enter Values Using Comma ',':")
n=var.split(",") # for constructing list from sequence
d=tuple(n)        # for constructing tuple

print ("List is :",n)
print ("Tuple is :",d)



Output: