Python Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ASSIGNMENT -1

1]Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ?


a) [2, 33, 222, 14].
b) Error
c) 25
d) [25, 14, 222, 33, 2].

2]. What is the output when following code is executed ?


names =['Amir', 'Bear', 'Charlton', 'Daman']
print(names[-1][-1])
a) A
b) Daman
c) Error
d) n

3]What is the output when following code is executed ?


list1 =[1, 3]
list2 = list1
list1[0]=4
print(list2)
a) [1, 3].
b) [4, 3].
c) [1, 4].
d) [1, 3, 4].

4]Which of the following is not a declaration of the dictionary?


a) {1: ‘A’, 2: ‘B’}
b) dict([[1,”A”],[2,”B”]])
c) {1,”A”,2”B”}
d) { }

5]What is the output of the following code?


a={1:5,2:3,3:4}
a.pop(3)
print(a)
a) {1: 5}
b) {1: 5, 2: 3}
c) Error, syntax error for pop() method
d) {1: 5, 3: 4}
6] What will be the output of the following Python code?

nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
a) 7
b) Error, invalid syntax for formation of set
c) 4
d) 8

7]What will be the output of the following Python code?

a={1,2,3}
b=a
b.remove(3)
print(a)
a) {1,2,3}
b) Error, copying of sets isn’t allowed
c) {1,2}
d) Error, invalid syntax for remove

8]Is the following Python code valid?

a={3,4,{7,5}}
print(a[2][0])
a) Yes, 7 is printed
b) Error, elements of a set can’t be printed
c) Error, subsets aren’t allowed
d) Yes, {7,5} is printed

9]What will be the output of the following Python code?

a={4,5,6}
b={2,8,6}
print(a+b)
a) {4,5,6,2,8}
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) Error as the duplicate item 6 is present in both sets
10]What is the output?
d ={"john":40, "peter":45}
print(d["john"])
a) 40
b) 45
c) “john”
d) “peter”

11) What will be the output of the following Python code?

example = "snow world"


example[3] = 's'
print (example)

a) snow
b) snow world
c) Error
d) snos world

12) What will be the output of the following Python code?


print("xyyzxyzxzxyy".count('yy', 1))

a) 2
b) 0
c) 1
d) none of the mentioned

13) What will be the output of the following Python code?

print("abcdef".find("cd"))
a) True
b) 2
c) 3
d) None of the mentioned

14) Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
15]What is the output of the following piece of code when executed in Python shell?
a=("Check")*3
print(a)
a) (‘Check’,’Check’,’Check’)
b) * Operator not valid for tuples
c) ‘CheckCheckCheck’
d) Syntax error

16]What will be the output?


my_tuple=(1, 2, 3, 4)
my_tuple.append((5, 6, 7))
print len(my_tuple)
a) 1
b) 2
c) 5
d) Error

17) What is the output of the following code?


a=(1,2,3,4)
print(del(a[2]))
a) Now, a=(1,2,4)
b) Now, a=(1,3,4)
c) Now a=(3,4)
d) Error as tuple is immutable

You might also like