Formatting Python MCQs: Part 2 Multiple Choice Q&A

Formatting Python MCQs. Multiple Choice Questions on Formatting Part 2 And Booleans In Python Language.

Formatting Python MCQs

 

What will be the output of the following two codes ??

i. ‘{0}’.format(4.56)
ii. ‘{0}’.format([4.56,])

a) ‘4.56’, ‘4.56,’
b) ‘4.56’, ‘[4.56]’
c) 4.56, [4.56,]
d) 4.56, [4.56,]

 

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

‘%s’ %((1.23,),)

a) ‘(1.23,)’
b) 1.23,
c) (,1.23)
d) ‘1.23’

 

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

‘%.2f%s’ % (1.2345, 99)

a) ‘1.2345’, ‘99’
b) ‘1.2399’
c) ‘1.234599’
d) 1.23, 99

 

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

‘{0:f}, {1:2f}, {2:05.2f}’.format(1.23456, 1.23456, 1.23456)

a) Error
b) ‘1.234560, 1.22345, 1.23’
c) No output
d) ‘1.234560, 1.234560, 01.23’

Formatting Python MCQs

 

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

‘The {} side {1} {2}’.format(‘bright’, ‘of’, ‘life’)

a) Error
b) ‘The bright side of life’
c) ‘The {bright} side {of} {life}’
d) No output

 

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

D=dict(p=’my’, q=’android’)
‘{p}{q}’.format(**D)

a) Error
b) myandroid
c) my android
d) {‘my’, ‘android’}

 

What will be the output of the following Python code snippet ??

not(10<20) and not(10>30)

a) True
b) False
c) Error
d) No output

 

Which of the following Boolean expressions is not logically equivalent to the other three ??

a) not(-6<0 or-6>10)
b) -6>=0 and -6<=10
c) not(-6<10 or-6==10)
d) not(-6>10 or-6==10)

Formatting Python MCQs

 

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

if (9 < 0) and (0 < -9):
print(“hello”)
elif (9 > 0) or False:
print(“good”)
else:
print(“bad”)

a) error
b) hello
c) good
d) bad

 

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

class Truth:
pass
x=Truth()
bool(x)

a) pass
b) true
c) false
d) error

 

What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday) ??

[] or {}
{} or []

a) []
    {}

b) []
     []

c) {}
    []

d) {}
     {}

 

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

l=[1, 0, 2, 0, ‘hello’, ”, []]
list(filter(bool, l))

a) Error
b) [1, 0, 2, 0, ‘hello’, ”, []]
c) [1, 0, 2, ‘hello’, ”, []]
d) [1, 2, ‘hello’]

Formatting Python MCQs

 

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

[‘f’, ‘t’][bool(‘spam’)]

a) t
b) f
c) No output
d) Error

 

What will be the output of the following Python code snippet ??

x=3.3456789
‘%-6.2f | %05.2f | %+06.1f’ %(x, x, x)

a) ‘3.35 | 03.35 | +003.3’
b) ‘3.3456789 | 03.3456789 | +03.3456789’
c) Error
d) ‘3.34 | 03.34 | 03.34+’

 

What will be the output of the following Python code snippet ??

x=3.3456789
‘%f | %e | %g’ %(x, x, x)

a) Error
b) ‘3.3456789 | 3.3456789+00 | 3.345678’
c) ‘3.345678 | 3.345678e+0 | 3.345678’
d) ‘3.345679 | 3.345679e+00 | 3.34568’

 

What will be the output of the python code shown below for various styles of format specifiers ??

x=1234
res=’integers:…%d…%-6d…%06d’ %(x, x, x)
res

a) ‘integers:…1234…1234 …001234’
b) ‘integers…1234…1234…123400’
c) ‘integers:… 1234…1234…001234’
d) ‘integers:…1234…1234…001234’

Formatting Python MCQs

 

The output of which of the codes shown below will be: “There are 4 blue birds.” ??

a) ‘There are %g %d birds.’ %4 %blue
b) ‘There are %d %s birds.’ %(4, blue)
c) ‘There are %s %d birds.’ %[4, blue]
d) ‘There are %d %s birds.’ 4, blue

 

What will be the output of the following Python code snippet ??

‘%d %s %g you’ %(1, ‘hello’, 4.0)

a) Error
b) 1 hello you 4.0
c) 1 hello 4 you
d) 1 4 hello you

 

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

‘{a}{b}{a}’.format(a=’hello’, b=’world’)

a) ‘hello world’
b) ‘hello’ ‘world’ ‘hello’
c) ‘helloworldhello’
d) ‘hello’ ‘hello’ ‘world’

 

The output of the two codes shown below is the same ??

i. bin((2**16)-1)
ii. ‘{}’.format(bin((2**16)-1))

a) True
b) False

Formatting Python MCQs

 

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

hex(255), int(‘FF’, 16), 0xFF

a) [0xFF, 255, 16, 255]
b) (‘0xff’, 155, 16, 255)
c) Error
d) (‘0xff’, 255, 255)

 

The formatting method {1:<10} represents the ___________ positional argument, _________ justified in a 10 character wide field ??

a) first, right
b) second, left
c) first, left
d) second, right

 

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

l=list(‘HELLO’)
p=l[0], l[-1], l[1:3]
‘a={0}, b={1}, c={2}’.format(*p)

a) Error
b) “a=’H’, b=’O’, c=(E, L)”
c) “a=H, b=O, c=[‘E’, ‘L’]”
d) Junk value

 

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

l=list(‘HELLO’)
‘first={0[0]}, third={0[2]}’.format(l)

a) ‘first=H, third=L’
b) ‘first=0, third=2’
c) Error
d) ‘first=0, third=L’

Formatting Python MCQs

 

What will be the output of the following Python code snippet ??

not(3>4)
not(1&1)

a) True
     True

b) True
     False

c) False
    True

d) False
     False

 

What will be the output of the following Python code snippet ??

[‘hello’, ‘morning’][bool(”)]

a) error
b) no output
c) hello
d) morning

 

What will be the output of the following Python code snippet ??

bool(‘False’)
bool()

a) True
     True

b) False
     True

c) False
    False

d) True
     False

 

Read More

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!