QuestionQ2

Python Basics

What output is produced by the following line of code entered in a Python interactive session?

>>> print (int(`1111`,2))  
  • A 1111
  • B 16
  • C ג€1111ג€
  • D 15
Explanation

In Python 2, backticks convert the integer 1111 to its string representation, '1111'. Converting that value with base 2 interprets it as the binary number 1111, whose decimal value is 15.

Community Discussion

No comments yet. Be the first to start the discussion!