What will be the output of the following Python code?
x = 'abcd'for i in x: print(i) x.upper()
a B C D
a b c d
A B C D
error
d = {0, 1, 2}for x in d.values(): print(x)
0 1 2
None None None
none of the mentioned
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
What will be the output of the following Python code snippet?
print('abcdefcdghcd'.split('cd', 2))
[‘ab’, ‘ef’, ‘ghcd’]
[‘ab’, ‘efcdghcd’]
[‘abcdef’, ‘ghcd’]
What is the output of the following program:
print ("Hello World"[::-1])
dlroW olleH
Hello Worl
D
print("abcdef".find("cd") == "cd" in "abcdef")
True
False
Error
None of the mentioned
print('xyxxyyzxxy'.lstrip('xyy'))
zxxy
xyxxyyzxxy
xyxzxxy
str1="helloworld"print(str1[::-1])
dlrowolleh
hello
world
helloworld
a=["Apple","Ball","Cobra"]a.sort(key=len)print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
example = "NITIN" print(example.rfind("N"))
-1
4
3
1
set
tuple
string
None of These
print("xyyzxyzxzxyy".endswith("xyy", 0, 2))
0
index()
find()
Both of the above
None of the above
print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
xyyxyyxyxyxxy
12y12y1212x12
list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
a={5,5,6,7}
a={5,6,7}
Error as there is no add function for set data type
Error as 5 already exists in the set
What is the output of the following code?
a = set('dcma')b = set('mlpc')print(a^b)
{‘d’, ‘c’, ‘m’, ‘l’, ‘p’, ‘c’}
{‘m’, ‘l’, ‘p’, ‘c’}
{‘d’, ‘c’, ‘m’, ‘a’}
empty_tuple = ()
empty_tuple = tuple()
empty_tuple = []
Both A and B
a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count) print(a)
An exception is thrown
6
2
x = 'abcd'for i in range(len(x)): x[i].upper()print (x)
abcd
ABCD
getkeys()
key()
keys()
What does the following code print ?
x = 'mohan'for i in range (len(x)): x[i].upper()print (x)
mohan
MOHAN
print('abcd'.partition('cd'))
(‘ab’, ‘cd’, ”)
(‘ab’, ‘cd’)
d = {"john":40, "peter":45}print(d["john"])
40
45
“john”
“peter”
What will be the output of the following code snippet?
a=[1,2,3,4,5,6,7,8,9]a[::2]=10,20,30,40,50,60print(a)
ValueError: attempt to assign sequence of size 6 to extended slice of size 5
[10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
[1, 2, 10, 20, 30, 40, 50, 60]
[1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
word1="Apple" word2="Apple" list1=[1,2,3] list2=[1,2,3] print(word1 is word2) print(list1 is list2)
True True
False True
False False
True False
input(“Enter a string”)
eval(input(“Enter a string”))
enter(“Enter a string”)
eval(enter(“Enter a string”))
def f(values): values[0] = 44 v = [1, 2, 3]f(v)print(v)
[1, 44]
[1, 2, 3, 44]
[44, 2, 3]
[1, 2, 3]
Strings can be modified using indexing.
Strings are immutable.
Strings can only contain alphabetic characters.
Strings must end with a newline character.
s={abs}
s={4, ‘abc’, (1,2)}
s={2, 2.2, 3, ‘xyz’}
s={san}
Heeeo
Heelo
Heleo
None
String
List
Tuple
Dictionary
myList = [1, 5, 5, 5, 5, 1]max = myList[0]indexOfMax = 0for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)
copy()
upper()
capitalize()
length
length()
len()
What will be the output of following statement ?
>>>"m"+"n1"
'm+nl'
'mn1'
'm n1'
'm'
print('abcdefcdghcd'.split('cd'))
[‘ab’, ‘ef’, ‘gh’]
[‘ab’, ‘ef’, ‘gh’, ”]
(‘ab’, ‘ef’, ‘gh’)
(‘ab’, ‘ef’, ‘gh’, ”)
a={5,6,7,8}b={7,8,9,10} print(len(a+b))
8
Error, unsupported operand ‘+’ for sets
Nothing is displayed
5
List is mutable & Tuple is immutable
List is immutable & Tuple is mutable
Both List and Tuple are Mutable
Both List and Tuple are Immutable
list1 = [11, 2, 23]list2 = [11, 2, 2]print(list1 < list2)
print('ab cd-ef'.title())
Ab cd-ef
Ab Cd-ef
Ab Cd-Ef
startswith()
startswith_prefix()
startswithwith()
startswiths()
a={} a[2]=1 a[1]=[2,3,4] print(a[1][1])
[2,3,4]
print(''.isdigit())
print('1Rn@'.lower())
n
1rn@
rn
r
string = "my name is x"for i in string.split(): print (i, end=", ")
m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
(1, 2, 3)
{1, 2, 3}
{}
numbers = {}letters = {}comb = {}numbers[1] = 56numbers[3] = 7letters[4] = 'B'comb['Numbers'] = numbers comb['Letters'] = lettersprint(comb)
Error, dictionary in a dictionary can’t exist
‘Numbers’: {1: 56, 3: 7}
{‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}
{‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}
list
dict