Python output from print(print(print('aaa')))

前端 未结 5 632
梦如初夏
梦如初夏 2020-12-20 18:16

I don\'t quite understand output received from:

print(print(print(\'aaa\')))

aaa

None

None

F

5条回答
  •  伪装坚强ぢ
    2020-12-20 18:55

    Here is an example which does the same thing, and you will understand it better:

    def f():
        print('Hello')
    print(f())
    

    Outputs:

    Hello
    None
    

    None is at the end because you are basically doing print(print('Hello')), print writes something in the python interpreter and also when you do type(print()) it outputs: So this part is print(None).

    So that's why the output of print(print(print('aaa'))) includes None's

提交回复
热议问题