what is tuple in python?
Tuple is used to store multiple variables, a method or parameters. It stores multiple variables using a tuple that is stored in an array.
Example-
a = tuple([‘apple’,’red’,’apple’, ‘orange’, ‘red’])
print(a)
a[0]
Output:-
(‘apple’,’red’,’apple’, ‘orange’,’red’)
Sparkdatabox provides best python training in Coimbatore .Learn from Selenium Experts.Work on live live project and move towards success.
What is tuple of list?
A list is an ordered collection of items, tuple is the one in which all items are placed in order
Example-
a = tuple([1, 2, 3, 4, 5, 6])
print(a)
a[1]
Output:
6
What is tuple of tuples?
A tuple is a grouping of tuples
Example-
a = tuple(((‘apple’,’red’), (‘orange’, ‘red’), (‘brianc’), ‘red’))
print(a)
a[0][0]
Output:-
apple,orange,brianc
What is list?
In Python, a list can be treated as an ordered collection of elements
Example-
1,2,3 [‘apple’,’red’,’apple’, ‘orange’, ‘red’]
What is dictionaries?
A dictionary is an unordered collection of items
Example- {‘apple’: ‘red’,’orange’: ‘red’}
What is class in python?
A class is a blueprint, that is a way of creating objects and their characteristics
Example-
class Apple: def __init__(self,colour,size):
self.colour=colour
self.size=size
def print_colour(self):
print(self.colour)
def print_size(self):
print(self.size)
What is function?
A function is a procedure with its own name that we can call in Python
Example-
def hello():
print(“hello!”)
def add(a,b):
return a+b