Question: 1 . Given the list l = [ 1 , 2 , 3 , 4 , 5 ] , what is the result of l

1. Given the list l =[1,2,3,4,5], what is the result of l[-1]?
a)1
b)2
c)5
d) Error
2. How can a tuple t =(1,2,3) be appended to a list l =[4,5]?
a) l.append(t)
b) l.extend(t)
c) l.insert(0, t)
d) l += t
3. What does the following code snippet output?
for i in range(5):
if i ==3:
break
print(i)
a)012
b)0123
c)123
d)01234
4. In the statement names =';'.join(['Pedro', 'Khan', 'Kara']), the variable names is a: a) String
b) List
c) Tuple
d) Dictionary
5. What is the result of type(3.5+8) in Python?
a) int
b) float
c) str
d) float and int
6. Which statement about Python lists is true?
a) Lists are immutable.
b) Lists cannot contain different data types.
c) Lists may be ordered and mutable.
d) Lists do not allow duplicate elements.
7. What is the output of the following code?
def func(x, y):
return x * y
print(func(2, 'Python'))
a) PythonPython
b) Error
c)2Python
d) Python
8. Given the following dictionary, which operation will throw an error?
d ={'name': 'John', 'age': 30}
a) print(d['name'])
b) d['gender']= 'male'
c) print(d.get('age'))
d) print(d['salary'])
9. What does the following function do?
def mystery(l):
if len(l)<2:
return (l)
else:
return [l[-1]]+ mystery(l[:-1])
a) Reverses the list
b) Removes the last element from the list
c) Creates a new list with the last element repeated
d) Returns the original list unmodified
10. What is the result of the following list operation?
nums =[1,2,3]
vals = nums
del vals[:]
print(nums)
a)[1,2,3]
b)[]
c)[2]
d) Throws an error
11. What is the output of this code snippet?
def fun(inp=2, out=3):
return inp * out
print(fun(out=2))
a)4 b)6
c)8 d) Error
12. Consider the following code segment:
x =0.1
y =0.2
print(x + y ==0.3)
a) True b) False
c) Error d) None of the above
13. What is the final value of x after this code is executed?
x =1
for _ in range(3):
x += x
print(x)
a)3 b)6
c)8 d)12
14. What does the following Python code output?
numbers =[100,200,300,400,500]
sorted_numbers = sorted(numbers, reverse=True)
print(numbers[2], sorted_numbers[2])
a)300,300 b)200,300
c)300,200 d)200,400
15. What is the result of the following code?
my_list =[1,2,3,4,5]
print(my_list[::-1][1:4])
a)[4,3,2]
b)[3,2,1]
c)[4,3]
d)[4,3,2,1]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!