2
fantasy
6y

Can someone please tell me why output are 2 ?
1
Not 1
2

Comments
  • 1
    Wait you mean

    2 \n 1

    is the output?
    Then it is simple:

    1.Prints ‘2’
    OUTPUT:2

    2.Calls A’s ‘spam()’:
    1.Prints ‘1’
    OUTPUT:1

    So, final I output:

    2
    1
  • 6
    You are calling print(2) earlier than the spam function of A, you should switch them if you want them in the correct order.
  • 1
    @marci010101 Welcome to Devrant, I got your first ++
  • 3
    @RedBorg wow, thanks :*
  • 0
    @marci010101 so super().spam() = print(2)
    B().spam = print(1) ?
  • 1
    @fantasy yep, or just
    super().spam()
    print(2)
  • 0
    Because Python
  • 0
    ; evaluates left arg first
Add Comment