Python/ Sample Test,Sample questions

Question:
Anshu created two dictionaries “D1” and “D2” in python. Later on she wants to add all the elements of D2 in D1. As a friend of Anshu, help her to write the code.

1.D1.update(D2)

2.D2.update(D1)

3.D1.append(D2)

4.D2.append(D1)

Posted Date:-2021-12-06 18:28:45


Question:
Dhriti wants to create a dictionary with “Jan”, “Feb”, “Mar” as key and 31, 28, 31 as values respectively. Help her to write the correct code.

1.D = {“Jan” : 31, “Feb” : 28, “Mar” : 31}

2.D = [“Jan”:31, “Feb”:28, “Mar”:31]

3.D = {“Jan” ; 31, “Feb” ; 28, “Mar” ; 31}

4.D = (“Jan”:31, “Feb”:28, “Mar”:31)

Posted Date:-2021-12-06 18:32:43


Question:
Parth wants to display the value corresponding to the key “3” in dictionary given below. As a friend of Parth, help him to find the correct code.D={1: ‘Amit’, 2: ‘Suman’, 3: ‘Ravi’, 4: ‘Anuj’}

1.print(D.get(3))

2.print(D.get(3))

3.Both of the above

4.None of the above

Posted Date:-2021-12-06 18:38:49


Question:
Which operator is used to check if the key is present in the dictionary or not?

1.Mathematical Operator

2.Relational Operator

3.Membership Operator

4.Logical Operator

Posted Date:-2021-12-06 18:35:22


Question:
Write the output of the following :
D={1: 'Amit', 2: 'Suman', 3: 'Ravi', 4: 'Anuj'}
print(tuple(D))

1.((1,”Amit”, (2, “Suman”), (3, “Ravi”), (4, “Anuj”))

2.(1, 2, 3, 4)

3.(“Amit”, “Suman”, “Ravi”, “Anuj”)

4.None of the above

Posted Date:-2021-12-06 18:40:08


Question:
Write the output of the following:
D={1: ['Amit',23,21], 2: ['Suman',45,34], 3: 'Ravi', 4: 'Anuj'}
m = D.get(2)
print(m[2])

1.. 34

2.45

3.m

4.Suman

Posted Date:-2021-12-06 18:37:28


Question:
Write the output of the following:
D={1: ['Amit',23,21], 2: ['Suman',45,34], 3: 'Ravi', 4: 'Anuj'}
print("Amit" in D)

1.True

2.False

3.Error

4.None of the above

Posted Date:-2021-12-06 18:34:30


More MCQS

  1. help4info.com
  2. help4info.com
  3. help4info.com
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!