Search Placementyogi.com
 

Python Objective Questions and Answers

  :: Topics ::

6

What does the following expression print? Consider python 2.x

print type(5/2)

A.

<type 'float'>

B.

<type 'int'>

C.

<type 'number'>

D.

<type 'tuple'>

E.

<class 'int'>

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

In Python 2.x if you divide an integer by an integer, it returns an integer and truncates the decimal part.

>>> print type(5/2)

<type 'int'>

To get a float value any one of the operand has to be a float. 

>>> print 5.0/2

2.5

 
 

Banner to LogicGuns.com

Hide Page Information