Python/ Sample Test,Sample questions

Question:
 What is the two’s complement of -44?

1. 1011011

2. 11010100

3.11101011

4.10110011

Posted Date:-2021-12-30 01:17:51


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

x=3.3456789
'%s' %x, str(x)

1. Error

2.(‘3.3456789’, ‘3.3456789’)

3.(3.3456789, 3.3456789)

4.(‘3.3456789’, 3.3456789)

Posted Date:-2021-12-30 01:32:43


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

'{0:.2f}'.format(1.234)

1.‘1’

2. ‘1.234’

3.‘1.23’

4.‘1.2’

Posted Date:-2021-12-30 01:37:10


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

'{0:.2f}'.format(1.234)

1.‘1’

2. ‘1.234’

3.‘1.23’

4.‘1.2’

Posted Date:-2021-12-30 01:37:14


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

print("-%06d"%x)

1. -000122

2.000122

3.–00122

4.-00122

Posted Date:-2021-12-30 01:23:40


Question:
 What will be the output of the following Python expression?

bin(29)

1.‘0b10111’

2.‘0b11101’

3.‘0b11111’

4.‘0b11011’

Posted Date:-2021-12-30 00:25:08


Question:
 What will be the value of the following Python expression?

 bin(10-2)+bin(12^4)

1. 0b10000

2.0b10001000

3.0b1000b1000

4.0b10000b1000

Posted Date:-2021-12-30 01:16:36


Question:
Any odd number on being AND-ed with ________ always gives 1. Hint: Any even number on being AND-ed with this value always gives 0.

1. 10

2.2

3.1

4. 0

Posted Date:-2021-12-30 01:16:11


Question:
Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.

1.OR

2.AND

3.XOR

4. NOT

Posted Date:-2021-12-30 01:15:22


Question:
The expression shown below results in an error.

print("-%5d0",989)

1.Error

2.1 hello you 4.0

3. 1 hello 4 you

4.1 4 hello you

Posted Date:-2021-12-30 01:30:47


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

1.first, right

2.second, left

3.first, left

4.second, right

Posted Date:-2021-12-30 01:39:44


Question:
The one’s complement of 110010101 is:

1.001101010

2.110010101

3.001101011

4.110010100

Posted Date:-2021-12-30 00:47:34


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

1.‘There are %g %d birds.’ %4 %blue

2. ‘There are %d %s birds.’ %(4, blue)

3.There are %s %d birds.’ %[4, blue]

4.‘There are %d %s birds.’ 4, blue

Posted Date:-2021-12-30 01:31:19


Question:
To find the decimal value of 1111, that is 15, we can use the function:

1.int(1111,10)

2.int(‘1111’,10)

3. int(1111,2)

4. int(‘1111’,2)

Posted Date:-2021-12-30 00:26:21


Question:
What is the value of the following Python expression?

bin(0x8)

1.‘0bx1000’

2. 8

3.1000

4. ‘0b1000’

Posted Date:-2021-12-30 00:33:12


Question:
What will be the output of the following Python code if a=10 and b =20?

a=10
b=20
a=a^b
b=a^b
a=a^b
print(a,b)

1.10 20

2.10 10

3. 20 10

4.20 20

Posted Date:-2021-12-30 01:17:27


Question:
What will be the output of the following Python code snippet if x=1?

x<<2

1. 8

2. 1

3. 2

4. 4

Posted Date:-2021-12-30 00:24:38


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

['hello', 'morning'][bool('')]

1. error

2.no output

3.hello

4.morning

Posted Date:-2021-12-30 01:19:05


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

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

1.Error

2. No output

3. ‘1 more foods’

4. ‘1 more spam’

Posted Date:-2021-12-30 01:33:09


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

a='hello'
q=10
vars()

1. {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}

2.{……Built in names set by Python……}

3.{‘a’ : ‘hello’, ‘q’ : 10}

4. Error

Posted Date:-2021-12-30 01:34:14


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

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

1. True

2.False

3.Error

4.No output

Posted Date:-2021-12-30 01:20:46


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

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

1. ‘3.35 | 03.35 | +003.3’

2. ‘3.3456789 | 03.3456789 | +03.3456789’

3. Error

4.‘3.34 | 03.34 | 03.34+’

Posted Date:-2021-12-30 01:32:14


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

x=3.3456789
'%f | %e | %g' %(x, x, x)

1.Error

2.‘3.3456789 | 3.3456789+00 | 3.345678’

3. ‘3.345678 | 3.345678e+0 | 3.345678’

4.‘3.345679 | 3.345679e+00 | 3.34568’

Posted Date:-2021-12-30 01:31:50


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

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

1.00000hi

2.000hi

3.hi000

4. error

Posted Date:-2021-12-30 01:21:22


Question:
What will be the output of the following Python code snippet?
X=”san-foundry”
print(“%56s”,X)

1.56 blank spaces before san-foundry

2. 56 blank spaces before san and foundry

3.56 blank spaces after san-foundry

4. no change

Posted Date:-2021-12-30 01:21:53


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

['f', 't'][bool('spam')]

1.t

2.f

3.No output

4.error control

Posted Date:-2021-12-30 01:19:29


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

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

1. Error

2. ‘2.5, 10, [1, 2]’

3.2.5, 10, 1, 2

4.’10, 2.5, [1, 2]’

Posted Date:-2021-12-30 01:36:37


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

'%x %d' %(255, 255)

1. ‘ff, 255’

2.‘255, 255’

3. ‘15f, 15f’

4.error control

Posted Date:-2021-12-30 01:37:44


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

l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))

1.Error

2. [1, 0, 2, 0, ‘hello’, ”, []]

3.[1, 0, 2, ‘hello’, ”, []]

4.[1, 2, ‘hello’]

Posted Date:-2021-12-30 01:19:55


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

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

1.‘first=H, third=L’

2.‘first=0, third=2’

3. Error

4.‘first=0, third=L’

Posted Date:-2021-12-30 01:38:51


Question:
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)

1.Error

2.“a=’H’, b=’O’, c=(E, L)”

3.“a=H, b=O, c=[‘E’, ‘L’]”

4. Junk value

Posted Date:-2021-12-30 01:39:16


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

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

1. ‘hello good and morning’

2. ‘hello, good, morning’

3. ‘hello, good, and morning’

4. error

Posted Date:-2021-12-30 01:34:52


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

s='%s, %s & %s'
s%('mumbai', 'kolkata', 'delhi')

1.mumbai kolkata & delhi

2.Error

3.No output

4. ‘mumbai, kolkata & delhi’

Posted Date:-2021-12-30 01:35:24


Question:
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')

1. ‘hello, world, universe’

2. ‘hellos, worlds, universes’

3. Error

4.hellos, world, universe

Posted Date:-2021-12-30 01:35:53


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

print(“%f”%x)

1.34.00

2.34.0000

3.34.000000

4.34.00000000

Posted Date:-2021-12-30 01:24:04


Question:
What will be the output of the following Python expression if x=15 and y=12?

x & y

1.b1101

2.0b1101

3.12

4. 1101

Posted Date:-2021-12-30 00:26:45


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

print("%5.2f"%x)

1.22.1900

2.22.00000

3. 22.19

4.22.20

Posted Date:-2021-12-30 01:25:05


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

print(“%06d”%X)

1. 345000

2.000345

3.000000345

4. 345000000

Posted Date:-2021-12-30 01:22:37


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

print("%-06d"%x)

1.000456

2.456000

3. 456

4. error

Posted Date:-2021-12-30 01:22:15


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

print("%.2f"%x)

1.56.00

2.56.24

3.56.23

4.0056.236

Posted Date:-2021-12-30 01:24:38


Question:
What will be the output of the following Python expression?

~100?

1.101

2. -101

3.100

4.-100

Posted Date:-2021-12-30 01:18:24


Question:
What will be the output of the following Python expression?

0x35 | 0x75

1.115

2.116

3.117

4.118

Posted Date:-2021-12-30 00:34:47


Question:
What will be the output of the following Python expression?

4^12

1.2

2. 4

3.8

4.12

Posted Date:-2021-12-30 01:15:48


Question:
What will be the output of the following Python expression?

int(1011)?

1.1011

2.11

3. 13

4. 1101

Posted Date:-2021-12-30 00:25:54


Question:
What will be the value of x in the following Python expression, if the result of that expression is 2?

x>>2

1. 8

2.4

3.2

4.1

Posted Date:-2021-12-30 00:25:29


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

1.not(-6<0 or-6>10)

2.-6>=0 and -6<=10

3.not(-6<10 or-6==10)

4.not(-6>10 or-6==10)

Posted Date:-2021-12-30 01:20:24


Question:
Which of the following expressions can be used to multiply a given number ‘a’ by 4?

1. a<<2

2. a<<4

3. a>>2

4. a>>4

Posted Date:-2021-12-30 01:17:01


Question:
Which of the following expressions results in an error?

1.int(1011)

2. int(‘1011’,23)

3. int(1011,2)

4.int(‘1011’)

Posted Date:-2021-12-30 00:27:16


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

1.print(“-ns”%S)

2. print(“-ns”%S)

3.print(“%ns”%S)

4. print(“%-ns”%S)

Posted Date:-2021-12-30 01:23:01


Question:
Which of the following represents the bitwise XOR operator?

1.&

2. ^

3. |

4. !

Posted Date:-2021-12-30 00:32:08


More MCQS

  1. help4info.com
  2. help4info.com
  3. help4info.com
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!