+ 1
isnt writing >>>'hello world' and >>>print('hello world') same thing?if not whats the difference?
help?
2 Réponses
+ 1
No, they are not the same.
Simply writing 'hello world' in Pyhton Shell (IDLE) will do the trick only because this is how the shell interpretes user input.
In _real_ script you will get an error.
IDLE interpretes simple 'hello world' as an unnamed str-type variable.
But if you try to do this:
>>> 'hello world', 555
IDLE will give you a tuple as a result
while
>>> print('hello world', 555)
will give you desired combined string as an output.
That is why I always recommend to use functions and methods in canonical forms. If you need to print something - use print function to make your code less obfuscated.
>>> 'hello world'
'hello world'
>>> print(type(_))
<class 'str'>
>>> 'hello world', 555
('hello world', 555)
>>> print(type(_))
<class 'tuple'>
>>>
0
I think printing a string will not include the quotes while as quotes, single or double are added when not using print for instance when writing a string directly in prompt.