Python

Python

Strings has 104 Questions
What is the output of the following?
print("xyyzxyzxzxyy".count('xyy', 0, 100))

2
0
1
error
What is the output of the following?
print("xyyzxyzxzxyy".count('xyy', 2, 11))

2
0
1
error
What is the output of the following?
print("xyyzxyzxzxyy".count('xyy', -10, -1))

2
0
1
error
What is the output of the following?
print('abc'.encode())


abc
'abc'
b'abc'
h'abc'
What is the output of the following?
print("ab\tcd\tef".expandtabs())

ab   cd    ef
abcdef
ab\tcd\tef
ab     cd   ef
What is the output of the following?
print("abcdef".find("cd"))

True
2
3
none of the mentioned
What is the output of the following?
print("ccdcddcd".find("c"))

4
0
error
True
What is the output of the following?
print("Hello {0} and {1}".format('foo', 'bin'))

Hello foo and bin
Hello {0} and {1} foo bin
error
Hello 0 and 1
What is the output of the following?
print("Hello {} and {}".format('foo', 'bin'))

Hello foo and bin
Hello {} and {}
error
Hello and
What is the output of the following?
print("Hello {name1} and {name2}".format('foo', 'bin'))

Hello foo and bin
Hello {name1} and {name2}
error
Hello and
What is the output of the following?
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))

Hello foo and bin
Hello {name1} and {name2}
error
Hello and
What is the output of the following?
print("Hello {0!r} and {0!s}".format('foo', 'bin'))

Hello foo and bin
Hello 'foo' and bin
Hello foo and 'bin'
error
What is the output of the following?
print("Hello {0} and {1}".format(('foo', 'bin')))

Hello foo and bin
Hello ('foo', 'bin') and ('foo', 'bin')
error
none of the mentioned
What is the output of the following?
print('The sum of {0} and {1} is {2}'.format(2, 10, 12))

The sum of 2 and 10 is 12
error
The sum of 0 and 1 is 2
none of the mentioned
What is the output of the following?
print('The sum of {0:b} and {1:x} is {2:o}'.format(2, 10, 12))

The sum of 2 and 10 is 12
The sum of 10 and a is 14
The sum of 10 and a is c
error
What is the output of the following?
print('{:,}'.format(1112223334))

1,112,223,334
111,222,333,4
1112223334
error
What is the output of the following?
print('{:,}'.format('1112223334'))

1,112,223,334
111,222,333,4
1112223334
error
What is the output of the following?
print('{:$}'.format(1112223334))

1,112,223,334
111,222,333,4
1112223334
error
What is the output of the following?
print('{:#}'.format(1112223334))

1,112,223,334
111,222,333,4
1112223334
error
What is the output of the following?
print('{0:.2}'.format(1/3))

0.333333
0.33
0.333333:.2
error
What is the output of the following?
print('{0:.2%}'.format(1/3))

0.33
0.33%
33.33%
33%
What is the output of the following?
print('ab12'.isalnum())

True
False
None
error
What is the output of the following?
print('ab'.isalpha())

True
False
None
error
What is the output of the following?
print('a B'.isalpha())

True
False
None
error
What is the output of the following?
print('0xa'.isdigit())

True
False
None
error
What is the output of the following?
print(''.isdigit())

True
False
None
error
What is the output of the following?
print('my_string'.isidentifier())

True
False
None
error
What is the output of the following?
print('__foo__'.isidentifier())

True
False
None
error
What is the output of the following?
print('for'.isidentifier())

True
False
None
error
What is the output of the following?
print('abc'.islower())

True
False
None
error
What is the output of the following?
print('a@ 1,'.islower())

True
False
None
error
What is the output of the following?
print('1@ a'.isprintable())

True
False
None
error
What is the output of the following?
print('''
'''.isspace())

True
False
None
error
What is the output of the following?
print('\t'.isspace())

True
False
None
error
What is the output of the following?
print('HelloWorld'.istitle())

True
False
None
error
What is the output of the following?
print('Hello World'.istitle())

True
False
None
Error
What is the output of the following?
print('Hello!2@#World'.istitle())

True
False
None
error
What is the output of the following?
print('1Rn@'.lower())

n
1rn@
rn
r
What is the output of the following?
print('''
 \tfoo'''.lstrip())

\tfoo
foo
foo
none of the mentioned
What is the output of the following?
print('xyxxyyzxxy'.lstrip('xyy'))

zxxy
xyxxyyzxxy
xyxzxxy
none of the mentioned
What is the output of the following?
print('cba'.maketrans('abc', '123'))

{97: 49, 98: 50, 99: 51}
{65: 49, 66: 50, 67: 51}
321
123
What is the output of the following?
print('a'.maketrans('ABC', '123'))

{97: 49, 98: 50, 99: 51}
{65: 49, 66: 50, 67: 51}
{97: 49}
1
What is the output of the following?
print('abcdef'.partition('cd'))

('ab', 'ef')
('abef')
('ab', 'cd', 'ef')
2
What is the output of the following?
print('abcdefcdgh'.partition('cd'))

('ab', 'cd', 'ef', 'cd', 'gh')
('ab', 'cd', 'efcdgh')
('abcdef', 'cd', 'gh')
error
What is the output of the following?
print('abcd'.partition('cd'))

('ab', 'cd', "?)
('ab', 'cd')
error
none of the mntioned
What is the output of the following?
print('cd'.partition('cd'))

('cd')
("?)
('cd', "?, "?)
("?, 'cd', "?)
What is the output of the following?
print('abef'.partition('cd'))

('abef')
('abef', 'cd', "?)
('abef', "?, "?)
error
What is the output of the following?
print('abcdef12'.replace('cd', '12'))

ab12ef12
abcdef12
ab12efcd
none of the mentioned
What is the output of the following?
print('abcefd'.replace('cd', '12'))

ab1ef2
abcefd
ab1efd
ab12ed2
What is the output of the following?
print('xyyxyyxyxyxxy'.replace('xy', '12', 0))

xyyxyyxyxyxxy
12y12y1212x12
12yxyyxyxyxxy
xyyxyyxyxyx12
What is the output of the following?
print('xyyxyyxyxyxxy'.replace('xy', '12', 100))

xyyxyyxyxyxxy
12y12y1212x12
none of the mentioned
error
What is the output of the following?
print('abcdefcdghcd'.split('cd'))

['ab', 'ef', 'gh']
['ab', 'ef', 'gh', "?]
('ab', 'ef', 'gh')
('ab', 'ef', 'gh', "?)
What is the output of the following?
print('abcdefcdghcd'.split('cd', 0))

['abcdefcdghcd']
'abcdefcdghcd'
error
none of the mentioned
What is the output of the following?
print('abcdefcdghcd'.split('cd', -1))

['ab', 'ef', 'gh']
['ab', 'ef', 'gh', "?]
('ab', 'ef', 'gh')
('ab', 'ef', 'gh', "?)
What is the output of the following?
print('abcdefcdghcd'.split('cd', 2))

['ab', 'ef', 'ghcd']
['ab', 'efcdghcd']
['abcdef', 'ghcd']
none of the mentioned
What is the output of the following?
print('ab\ncd\nef'.splitlines())

['ab', 'cd', 'ef']
['ab\n', 'cd\n', 'ef\n']
['ab\n', 'cd\n', 'ef']
['ab', 'cd', 'ef\n']
What is the output of the following?
print('Ab!2'.swapcase())

AB!@
ab12
aB!2
aB1@
What is the output of the following?
print('ab cd-ef'.title())

Ab cd-ef
Ab Cd-ef
Ab Cd-Ef
none of the mentioned
What is the output of the following?
print('abcd'.translate('a'.maketrans('abc', 'bcd')))

bcde
abcd
error
none of the mentioned
What is the output of the following?
print('abcd'.translate({97: 98, 98: 99, 99: 100}))

bcde
abcd
error
none of the mentioned
What is the output of the following?
print('abcd'.translate({'a': '1', 'b': '2', 'c': '3', 'd': '4'}))

abcd
1234
error
none of the mentioned
What is the output of the following?
print('ab'.zfill(5))

000ab
00ab0
0ab00
ab000
What is the output of the following?
print('+99'.zfill(5))

00+99
00099
+0099
+++99
What is the output when following statement is executed ?
  1. >>>"a"+"bc"

a
bc
bca
abc
What is the output when following statement is executed ?
  1. >>>"abcd"[2:]

a
ab
cd
dc
The output of executing string.ascii_letters can also be achieved by:

string.ascii_lowercase_string.digits
string.ascii_lowercase+string.ascii_upercase
string.letters
string.lowercase_string.upercase
What arithmetic operators cannot be used with strings?

+
*
?=
**
What is the output when following code is executed ?
  1. >>>print r"\nhello"
The output

a new line and hello
\nhello
the letter r and then hello
Error
What is the output when following statement is executed ?
  1. >>>print 'new' 'line'

Error
Output equivalent to print 'new\nline'
newline
new line
What is the output when following statement is executed ?
  1. >>>print '\x97\x98'

Error
97 98
_~
\x97\x98
What is the output when following code is executed ?
  1. >>>str1="helloworld"
  2. >>>str1[::-1]

dlrowolleh
hello
world
helloworld
What is the output of the following code ?
  1. class father:
  2.     def __init__(self, param):
  3.         self.o1 = param
  4. ?
  5. class child(father):
  6.     def __init__(self, param):
  7.         self.o2 = param
  8. ?
  9. >>>obj = child(22)
  10. >>>print "%d %d" % (obj.o1, obj.o2)

None None
None 22
22 None
Error is generated
What is the output of the following code ?
  1. class tester:
  2.     def __init__(self, id):
  3.         self.id = str(id)
  4.         id="224"
  5. ?
  6. >>>temp = tester(12)
  7. >>>print temp.id

224
Error
12
None
What is the output of the following code ?
  1. >>>example = "snow world"
  2. >>>print "%s" % example[4:7]

wo
world
sn
rl
What is the output of the following code ?
  1. >>>example = "snow world"
  2. >>>example[3] = 's'
  3. >>>print example

snow
snow world
Error
snos world
What is the output of the following code ?
  1. >>>max("what are you")

Error
u
t
y
Given a string example="?hello"? what is the output of example.count(l)

2
1
None
0
What is the output of the following code ?
  1. >>>example = "helle"
  2. >>>example.find("e")


Error
-1
1
0
What is the output when following statement is executed ?
  1. >>>chr(ord('A'))

A
B
a
Error
What is the output when following statement is executed ?
  1. >>>print(chr(ord('b')+1))

a
b
c
A
Which of the following statement prints hello\example\test.txt.?

print("hello\example\test.txt"?)
print("hello\\example\\test.txt"?)
print("hello\"?example\"?test.txt"?)
print("hello"?\example"?\test.txt"?)
Suppose s is "\t\tWorld\n"?, what is s.strip()?

\t\tWorld\n
\t\tWorld\n
\t\tWORLD\n
World
The format function returns:

Error
int
bool
str
What is the output of "hello"?+1+2+3?

hello123
hello
Error
hello6
What is the output when following code is executed ?
  1. >>>print("D", end = ' ')
  2. >>>print("C", end = ' ')
  3. >>>print("B", end = ' ')
  4. >>>print("A", end = ' ')

DCBA
A, B, C, D
D C B A
A, B, C, D will be displayed on four lines
What is the output when following statement is executed ?(python 3.xx)
  1. >>>print(format("Welcome", "10s"), end = '#')
  2. >>>print(format(111, "4d"), end = '#')
  3. >>>print(format(924.656, "3.2f"))

???Welcome#?111#924.66
Welcome#111#924.66
Welcome#111#.66
Welcome???#?111#924.66
What will be displayed by print(ord('b') ? ord('a'))?

0
1
-1
2
Say s="?hello"? what will be the return value of type(s)?

int
bool
str
String
What is "Hello"?.replace("l"?, "e"?)

Heeeo
Heelo
Heleo
None
Suppose i is 5 and j is 4, i + j is same as

i.__add(j)
i.__add__(j)
i.__Add(j)
i.__ADD(j)
What is the output of the following code ?
  1. class Count:
  2.     def __init__(self, count = 0):
  3.        self.__count = count
  4. ?
  5. c1 = Count(2)
  6. c2 = Count(2)
  7. print(id(c1) == id(c2), end = " ")
  8. ?
  9. s1 = "Good"
  10. s2 = "Good"
  11. print(id(s1) == id(s2))

True False
True True
False True
False False
What function do you use to read a string?

input("Enter a string"?)
eval(input("Enter a string"?))
enter("Enter a string"?)
eval(enter("Enter a string"?))
Suppose x is 345.3546, what is format(x, "10.3f"?) (_ indicates spac)

__345.355
___345.355
____345.355
_____345.354
What is the output of the following?
print("abc DEF".capitalize())

abc def
ABC DEF
Abc def
Abc Def
What is the output of the following?
print("abc. DEF".capitalize())

abc def
ABC DEF
Abc def
Abc Def
What is the output of the following?
print("abcdef".center())

cd
abcdef
error
none of the mentioned
What is the output of the following?
print('*', "abcdef".center(7), '*')

* abcdef *
* abcdef *
*abcdef *
* abcdef*
What is the output of the following?
print('*', "abcde".center(6), '*', sep='')

* abcde *
* abcde *
*abcde *
* abcde*
What is the output of the following?
print("abcdef".center(7, 1))

1abcdef
abcdef1
abcdef
error
What is the output of the following?
print("abcdef".center(7, '1'))

1abcdef
abcdef1
abcdef
error
What is the output of the following?
print("abcdef".center(10, '12'))

12abcdef12
abcdef1212
1212abcdef
error
What is the output of the following?
print("xyyzxyzxzxyy".count('yy'))

2
0
error
none of the mentioned
What is the output of the following?
print("xyyzxyzxzxyy".count('yy', 1))

2
0
1
none of the mentioned
What is the output of the following?
print("xyyzxyzxzxyy".count('yy', 2))

2
0
1
none of the mentioned

You have to grow from the inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul.
Swami Vivekananda
The more we come out and do good to others, the more our hearts will be purified, and God will be in them.
Swami Vivekananda
You have to grow from the inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul.
Swami Vivekananda
The more we come out and do good to others, the more our hearts will be purified, and God will be in them.
Swami Vivekananda