If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.
1. obj.__str__()
2.str(obj)
3.print obj
4. all of the mentioned
Suppose s is “ World â€, what is s.strip()?
1. World
2. World
3. WORLD
4.World
To retrieve the character at index 3 from string s=â€Hello†what command do we execute (multiple answers allowed)?
1. s[]
2.s.getitem(3)
3.s.__getitem__(3)
4.s.getItem(3)
What will be the output of the following Python code? >>>print("D", end = ' ') >>>print("C", end = ' ') >>>print("B", end = ' ') >>>print("A", end = ' ')
1.DCBA
2. A, B, C, D
3. D C B A
4.D, C, B, A will be displayed on four lines
What will be the output of the following Python code? print("abc DEF".capitalize())
1.abc def
2.ABC DEF
3.Abc def
4. Abc Def
What will be the output of the following Python code? print(0xA + 0xB + 0xC)
1. 0xA0xB0xC
2.Error
3.0x22
4.33
What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i)
1. 0 1 2
2.error
3. 0 1 2 0 1 2
4.none of the mentioned
What will be the output of the following Python statement?(python 3.xx) >>>print(format("Welcome", "10s"), end = '#') >>>print(format(111, "4d"), end = '#') >>>print(format(924.656, "3.2f"))
1.Welcome# 111#924.66
2.Welcome#111#924.66
3.Welcome#111#.66
4.Welcome # 111#924.66
Given a string example=â€hello†what is the output of example.count(‘l’)?
1.2
2. 1
3.None
4.0
Say s=â€hello†what will be the return value of type(s)?
1.int
2.bool
3.str
4.String
Suppose i is 5 and j is 4, i + j is same as ________
1. i.__add(j)
2. i.__add__(j)
3. i.__Add(j)
4.i.__ADD(j)
Suppose x is 345.3546, what is format(x, “10.3fâ€) (_ indicates space).
1. __345.355
2.___345.355
3.___345.355
4._____345.354
The format function, when applied on a string returns ______
1. Error
2. int
3.bool
4.str
The output of executing string.ascii_letters can also be achieved by:
1.string.ascii_lowercase_string.digits
2.string.ascii_lowercase+string.ascii_uppercase
3.string.letters
4.string.lowercase_string.uppercase
To check whether string s1 contains another string s2, use ____
1.s1.__contains__(s2)
2.s2 in s1
3.s1.contains(s2)
4.si.in(s2)
To concatenate two strings to a third what statements are applicable?
1. s3 = s1 . s2
2.s3 = s1.add(s2)
3.s3 = s1.__add__(s2)
4. s3 = s1 * s2
To return the length of string s what command do we execute?
1.s.__len__()
2. len(s)
3. size(s)
4.s.size()
What arithmetic operators cannot be used with strings?
1. +
2.*
3.–
4.all of the mentioned
What function do you use to read a string?
1.input(“Enter a stringâ€)
2.eval(input(“Enter a stringâ€))
3.enter(“Enter a stringâ€)
4.eval(enter(“Enter a stringâ€))
What is “Helloâ€.replace(“lâ€, “eâ€)?
1.Heeeo
2.Heelo
3.Heleo
4. None
What will be displayed by print(ord(‘b’) – ord(‘a’))?
1.0
2. 1
3. -1
4. 2
What will be the output of the “hello†+1+2+3?
1. hello123
2. hello
3.Error
4. hello6
What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[-1] in a: print(a[-1])
1.0 1 2 3
2.0 1 2 2
3. 3 3 3 3
4.error
What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[0] in a: print(a[0])
1.0 1 2 3
2.0 1 2 2
3. 3 3 3 3
4.error
What will be the output of the following Python code snippet? a = [0, 1, 2, 3] i = -2 for i not in a: print(i) i += 1
1. -2 -1
2.0
3. error
4.none of the mentioned
What will be the output of the following Python code snippet? string = "my name is x" for i in ' '.join(string.split()): print (i, end=", ")
1.m, y, , n, a, m, e, , i, s, , x,
2.m, y, , n, a, m, e, , i, s, , x
3.my, name, is, x,
4.error
What will be the output of the following Python code? >>> str1 = 'hello' >>> str2 = ',' >>> str3 = 'world' >>> str1[-1:]
1.olleh
2.hello
3.h
4.o
What will be the output of the following Python code? >>>example = "helle" >>>example.find("e")
1.Error
2. -1
3.1
4.0
What will be the output of the following Python code? >>>example = "helle" >>>example.rfind("e")
1.-1
2.4
3. 3
4.1
What will be the output of the following Python code? >>>example = "snow world" >>>example[3] = 's' >>>print example
1. snow
2.snow world
3. Error
4.snos world
What will be the output of the following Python code? >>>example = "snow world" >>>print("%s" % example[4:7])
1.wo
2.world
3.sn
4.rl
What will be the output of the following Python code? >>>example="helloworld" >>>example[::-1].startswith("d")
1.dlrowolleh
2. True
3.-1
4.None
What will be the output of the following Python code? >>>max("what are you")
1.error
2.u
3. t
4. Y
What will be the output of the following Python code? >>>print (r" hello")
1. a new line and hello
2. hello
3.the letter r and then hello
4.error
What will be the output of the following Python code? >>>str1="helloworld" >>>str1[::-1]
1. dlrowolleh
2.hello
3.world
4.helloworld
What will be the output of the following Python code? for i in range(10): if i == 5: break else: print(i) else: print("Here")
1.0 1 2 3 4 Here
2.0 1 2 3 4 5 Here
3.0 1 2 3 4
4.1 2 3 4 5
What will be the output of the following Python code? print('*', "abcdef".center(7), '*')
1. * abcdef *
2.* abcdef *
3. *abcdef *
4. * abcdef*
What will be the output of the following Python code? print('*', "abcdef".center(7), '*', sep='')
1.* abcdef *
2.* abcdef *
3. *abcdef *
4.* abcdef*
What will be the output of the following Python code? print("abc. DEF".capitalize())
1.abc. def
2.ABC. DEF
3. Abc. def
4.Abc. Def
What will be the output of the following Python code? print("abcdef".center())
1.cd
2.abcdef
3. error
4.none of the mentioned
What will be the output of the following Python code? print("abcdef".center(0))
1. cd
2. abcdef
3. error
4.none of the mentioned
What will be the output of the following Python code? string = "my name is x" for i in string.split(): print (i, end=", ")
1.m, y, , n, a, m, e, , i, s, , x
2. m, y, , n, a, m, e, , i, s, , x
3.my, name, is, x,
4.error
What will be the output of the following Python code? string = "my name is x" for i in string: print (i, end=", ")
1.m, y, , n, a, m, e, , i, s, , x,
2.m, y, , n, a, m, e, , i, s, , x
3.my, name, is, x,
4. error
What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i) for i in x: print(i)
1. 0 1 2
2.error
3.0 1 2 0 1 2
4.none of the mentioned
What will be the output of the following Python statement? >>>"a"+"bc"
1.a
2.bc
3.bca
4.abc
What will be the output of the following Python statement? >>>"abcd"[2:]
1. a
2.ab
3.cd
4.dc
What will be the output of the following Python statement? >>>chr(ord('A'))
1.A
2. B
3. a
4. error
What will be the output of the following Python statement? >>>print('new' 'line')
1. Error
2.Output equivalent to print ‘new line’
3.newline
4.new line
What will be the output of the following Python statement? >>>print(chr(ord('b')+1))
1.a
2.b
3. c
4. A
Which of the following statement prints helloexample est.txt?
1.print(“helloexample est.txtâ€)
2.print(“hello\example\test.txtâ€)
3.print(“helloâ€exampleâ€test.txtâ€)
4.print(“helloâ€example†est.txtâ€)