IT109 Written Exam 3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the output to the code? def outer_fun(a, b): def inner_fun(c, d): return c + d return inner_fun(a, b) res = outer_fun(5, 10) print(res)

15

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student['name'])

John

True or False: Dictionary keys must be immutable

True

True or False: Python function always returns a value

True

True or False: .pop saves the deleted item

True

What is the purpose of **kwargs?

it allows us to pass a variable number of keyword arguments to a Python function.

What is the purpose of *args?

it allows us to pass a variable number of non-keyword arguments to a Python function

What is the purpose of .popitem()?

removes the last inserted item

How to change/add a value in a dictionary:

student['name'] = 'Oliver'

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student[1])

{'aa': 1, 'bb': 2}

What is the output of this code? sampleDict = dict([ ('first', 1), ('second', 2), ('third', 3) ]) print(sampleDict)

{'first': 1, 'second': 2, 'third': 3}

What is the output of this code? student = {("Hi", "You") : 1, "name" : 2, 4 : 3, 3.5 : 4} print(student)

{('Hi', 'You'): 1, 'name': 2, 4: 3, 3.5: 4}

True or False: dictionary keys can only be ints, floats, strings, tuples.

True

True or False: Values can be any datatype

True

What is the output of this code? dict1 = {"key1":1, "key2":2} dict2 = {"key2":2, "key1":1} print(dict1 == dict2)

True

True or False: In python, dictionaries are immutable

False

True or False: Python function doesn't return anything unless and until you add a return statement

False

True or False: This code creates an empty dictionary: sampleDict = dict{}

False

True or False: You call dictionary values by using index

False

True or False: Keys can be a list

False

True or False: The keys AND values are printed when looping through a dictionary

False, only loops through the keys

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student.get('name))

John

does del save the deleted item?

No

What is the output of this code? dict = {4: 5, 6:7, 4:0, 6:1} print(len(dict))

2

How many items does this list have? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')}

5

What is the output of this code? dict1 = {"name": "Mike", "salary": 8000} temp = dict1.pop("age") print(temp)

Error

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} var = del student['age'] print(var)

Error

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student['phone'])

Error

if an index can't find an item, what will it print?

Error

What is the output of this code? import find_index from my_module

Error, because it is not in the right order

What is the output to this code? def fun1(num): return num + 25 fun1(5) print(num)

Error, because the variable is mentioned outside of the function.

What is the output to the code? def display_person(*args): for i in args: print(i) display_person(name="Emma", age="25")

Error, use **kwargs instead

What happens when a dictionary has two identical keys but with different values?

It will only count the first occurrence, but not the second.

What is the output of this code: dict1 = {"name": "Mike", "salary": 8000} temp = dict1.get("age") print(temp)

None

if .get can't find an item, what will it print?

None

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} var2 = student.pop('courses') print(var2)

['Math', 'Physics', 'Geography', 'History']

How to delete a key value pair?

del student['age']

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student.items())

dict_items([('name', 'Oliver'), ('age', 25), ('courses', ['Math', 'Physics', 'Geography', 'History']), (1, {'aa': 1, 'bb': 2}), ('tupl', ('Hi', 'You'))])

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student.keys())

dict_keys(['name', 'age', 'courses', 1, 'tupl'])

What is the output of this code? student = {'name': 'John', 'age': 25, 'courses': ['Math', 'Physics', 'Geography', 'History'], 1: {'aa': 1, 'bb': 2}, 'tupl': ('Hi', 'You')} print(student.values())

dict_values(['Oliver', 25, ['Math', 'Physics', 'Geography', 'History'], {'aa': 1, 'bb': 2}, ('Hi', 'You')])

def display(**kwargs): for i in kwargs: print(i) display(emp="Kelly", salary=9000)

emp salary

How to assign nicknames to imported functions and variables?

from my_module import find_index as fi, test as t

What is the correct function call? def fun1(name, age): print(name, age)

fun1("Emma", age=23) OR fun1(age =23, name="Emma")


संबंधित स्टडी सेट्स

Respiratory Disease (Begin Exam 2 Material)

View Set

Chapter 15 Assessing Head & Neck Prep U

View Set