Select the correct answerWhat will be the output of the following Python code snippet?d_1 = {"code":10, "tantra":15}print(list(d_1.keys()))Options(“code”:10, “tantra”:15)['code', 'tantra'][“code”:10, “tantra”:15](“code”, “tantra”)
Question
Select the correct answerWhat will be the output of the following Python code snippet?d_1 = {"code":10, "tantra":15}print(list(d_1.keys()))Options(“code”:10, “tantra”:15)['code', 'tantra'][“code”:10, “tantra”:15](“code”, “tantra”)
Solution
The correct answer is ['code', 'tantra'].
Here's the step by step explanation:
-
The code snippet is creating a dictionary
d_1with keys "code" and "tantra" and corresponding values 10 and 15. -
The
keys()method is used to get a view object that displays a list of all the keys in the dictionary. -
The
list()function is used to convert that view object to a list. -
So, when you print that list, it will display the keys of the dictionary as a list, which are ['code', 'tantra'].
Similar Questions
What will be the output of the following Python code snippet?v=set('code')v.add('tantra')v.update(set(['p', 'q']))print(v)Options{'code', ‘p’, 'q', ‘tantra’}{'d', 't', 'a', 'n', 't', 'r,' 'a', 'p', 'q', 'o', 'e', 'c'}{‘c’, ‘o’, ‘d’, ‘e’, ‘p’,'q', ‘tantra’}{‘c’, ‘o’, ‘d’, ‘e’, [‘p’, 'q'], ‘tantra’}
Select the correct answerWhat will be the output of the following Python code snippet?ct = 'code'for i in range(len(ct)): i.upper()print (ct)Optionsc o d eerror0 1 2 3none of the mentioned
Select the correct answerWhat will be the output of the following Python code snippet?ct={}ct['c']=2ct['d']=[5,6,7]print(ct)Options{‘c’: 2, ‘d’: [5]}{'c': 2, 'd': [5, 6, 7]}{‘c’: [6], ‘d’: [5]}Exception is thrown
Select the correct answerWhat will be the output of the following Python function?print(len(["codetantra",12, 40, 16, "code", "tantra"]))Options6Error45
Select the correct answerWhat will be the output of the following Python code?>>>ct1="codetantra">>>ct1[:3]>>>Optionscododetacodetantrade
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.