3 ms·
>>> test(2) is None True
by codexon 8y ago
>>> test(2) is None
True
- nikofeyn 8y agoi guess that is true in python3 but it is not in python 2.7.
- xapata 8y agoFalse. You're just not familiar with how the REPL works. >>> None >>> print(None) None In the future, you might want to refrain from strong criticism of a thing you're not familiar with. That habit leads to all sorts of -isms.
- nikofeyn 8y agoi do know how the repl works. i explicitly tried it out. i defined the function just as i said and ran test(2) is None and got false. i just now went to try it out again at home and got true. i don't know what to tell you other than something must have got shadowed somewhere.
- pdonis 8y agoHere's what I get from the Python 3 REPL: peter@localhost:~$ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def test(x): ... "something" ... >>> test(2) is None True And Python 2: peter@localhost:~$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def test(x): ... "something" ... >>> test(2) is None True If you post such a transcript from your REPL session where you get False, it should be easier to tell what's different between your setup and mine (which is a stock Python install on Ubuntu 16.04). However, there is another even more direct experiment you could have run at the Python REPL to see what Python expressions return: just type the expression directly at the REPL and see what it prints back at you. In Python 3: peter@ToshibaSatellite:~$ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> "something" 'something' And in Python 2: peter@ToshibaSatellite:~$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "something" 'something' So, in your test function above, the expression "something" does return itself; it just does it inside the function, and that return value then gets thrown away when the function exits, because you didn't return it from the function itself.
- nikofeyn 8y agoi know how to use the repl. i moved between computers during comments and wasn't able to inspect my repl session where it originally returned false. as i mentioned, i must have redefined something or shadowed something which caused confusion, and i just didn't realize it at the time.