Python Formatting

Multiple Choice questions related to Formatting, Advanced Formatting, and Boolean in Python Language.

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

 

Formatting Python Multiple Choice Questions: MCQs Part 1

Formatting Python Multiple Choice Questions. Multiple Choice Questions on Formatting in Python Programming Language Part 1.

Formatting Python Multiple Choice Questions

 

What will be the output of the following Python expression if X=345 ??

print(“%06d”%X)

a) 345000
b) 000345
c) 000000345
d) 345000000

 

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

‘%x %d’ %(255, 255)

a) ‘ff, 255’
b) ‘255, 255’
c) ‘15f, 15f’
d) Error

 

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

‘{0:.2f}’.format(1.234)

a) ‘1’
b) ‘1.234’
c) ‘1.23’
d) ‘1.2’

 

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

‘{a}, {0}, {abc}’.format(10, a=2.5, abc=[1, 2])

a) Error
b) ‘2.5, 10, [1, 2]’
c) 2.5, 10, 1, 2
d) ’10, 2.5, [1, 2]’

MCQs Python

 

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

t = ‘%(a)s, %(b)s, %(c)s’
t % dict(a=’hello’, b=’world’, c=’universe’)

a) ‘hello, world, universe’
b) ‘hellos, worlds, universes’
c) Error
d) hellos, world, universe

 

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

s=’%s, %s & %s’
s%(‘mumbai’, ‘kolkata’, ‘delhi’)

a) mumbai kolkata & delhi
b) Error
c) No output
d) ‘mumbai, kolkata & delhi’

 

The expression is shown below results in an error ??

print(“-%5d0”,989)

a) True
b) False

 

What will be the output of the following Python expression if x=22.19 ??

print(“%5.2f”%x)

a) 22.1900
b) 22.00000
c) 22.19
d) 22.20

Formatting Python Multiple Choice Questions

 

What will be the output of the following Python expression if x=56.236 ??

print(“%.2f”%x)

a) 56.00
b) 56.24
c) 56.23
d) 0056.236

 

What will be the output of the following Python expression if the value of x is 34 ??

print(“%f”%x)

a) 34.00
b) 34.0000
c) 34.000000
d) 34.00000000

 

What will be the output of the following Python expression if X = -122 ??

print(“-%06d”%x)

a) -000122
b) 000122
c) –00122
d) -00122

 

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

s='{0}, {1}, and {2}’
s.format(‘hello’, ‘good’, ‘morning’)

a) ‘hello good and morning’
b) ‘hello, good, morning’
c) ‘hello, good, and morning’
d) Error

Formatting Python Multiple Choice Questions

 

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

a=’hello’
q=10
vars()

a) {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
b) {……Built in names set by Python……}
c) {‘a’ : ‘hello’, ‘q’ : 10}
d) Error

 

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

‘%(qty)d more %(food)s’ %{‘qty’:1, ‘food’: ‘spam’}

a) Error
b) No output
c) ‘1 more foods’
d) ‘1 more spam’

 

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

x=3.3456789
‘%s’ %x, str(x)

a) Error
b) (‘3.3456789’, ‘3.3456789’)
c) (3.3456789, 3.3456789)
d) (‘3.3456789’, 3.3456789)

 

Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’ ??

a) print(“-ns”%S)
b) print(“-ns”%S)
c) print(“%ns”%S)
d) print(“%-ns”%S)

Formatting Python Multiple Choice Questions

 

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

i. ‘{0:.2f}’.format(1/3.0)
ii. ‘%.2f’%(1/3.0)

a) True
b) False

 

What will be the output of the following Python expression if x=456 ??

print(“%-06d”%x)

a) 000456
b) 456000
c) 456
d) error

 

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

X=”my-android”
print(“%56s”,X)

a) 56 blank spaces before my-android
b) 56 blank spaces before my and android
c) 56 blank spaces after my-android
d) no change

 

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

X=”hi”
print(“05d”%X)

a) 00000hi
b) 000hi
c) hi000
d) error

 

error: Content is protected !!