"None" doesn't display as I expected in Python interactive mode

I thought that displaying in Python interactive mode is always equivalent print(repr()), but this is not the case for None. Is this a linguistic function or am I missing something? Thanks you

>>> None
>>> print(repr(None))
None
>>>
+4
source share
4 answers

Yes, this behavior is intentional.

From Python Docs

7.1. Expression Operators

( ) (), (, ; Python, None). . :

expression_stmt ::=  starred_expression

( ).

, None, string repr() ( , None, .)

+2

. python None, .

. , , None, .

, print() None, :

>>> print("hello")
hello
>>> y = print("hello")
hello
>>> y
>>> print(y)
None
+4

Python , , , None. , Python . , "", .

,

>>> a = 1
>>> a
1
>>>

>>> a = None
>>> a
>>>

+1

None , . - Python, __repr__ ; None .

. , , None ( ), , , , print(None) None , print None.

print(repr()) a TypeError Python.

+1

Source: https://habr.com/ru/post/1655477/


All Articles