Define a function list_type(),with no arguments. In this function:a. Create a list variable list1 that stores four elements: [1, 2.0, "3", True]b. Create a tuple variable tuple1 = (..., ..., ...) that stores the type of each elements in the list1 (Hint: use type function)c. Return list1 and tuple1
Question
Define a function list_type(),with no arguments. In this function:a. Create a list variable list1 that stores four elements: [1, 2.0, "3", True]b. Create a tuple variable tuple1 = (..., ..., ...) that stores the type of each elements in the list1 (Hint: use type function)c. Return list1 and tuple1
Solution
Here is the Python code that defines the function list_type():
def list_type():
# a. Create a list variable list1 that stores four elements: [1, 2.0, "3", True]
list1 = [1, 2.0, "3", True]
# b. Create a tuple variable tuple1 that stores the type of each elements in the list1
tuple1 = (type(list1[0]), type(list1[1]), type(list1[2]), type(list1[3]))
# c. Return list1 and tuple1
return list1, tuple1
You can call this function using list1, tuple1 = list_type(). This will return the list and tuple, and store them in list1 and tuple1 respectively.
Similar Questions
What will be the data type of z after the following statements?x = [1, 2, 3, 4] y = tuple(x) z = list(y)OptionsTypeErrortupleliststr
Fill in the blanks. __________ is a data-type in Python. a. List b. Tuple c. Dictionary d. All of these
What type of data is: z=[(2, 2),(3, 6),(7, 9)]?OptionsArray of tuplesTuples of listsInvalid typeList of tuples
Write a Python program to convert a list to a tuple
list, tuple, and range are the ___ of Data Types.Sequence TypesBinary TypesBoolean TypesNone of the mentioned above
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.