Reputation: 143
i'm new in the python world and i have small issue. im trying to run this action for example:
print ('Hello World')
print('1','2')
But i'm getting this output:
Hello World
('1','2')
Why the second row is not showing properly?
I'm using a mac laptop with python version 2.7
Thanks for the help.
Upvotes: 0
Views: 160
Reputation: 34398
You're trying to use the Python 3 print()
function, not the Python 2 print
command. However, you're trying to use this function in Python 2. Use from __future__ import print_function
to get this behavior in Python 2.
See also __future__
and PEP 3105.
Upvotes: 1
Reputation: 18727
Because ()
is used for grouping, it does not have an effect in the execution level but it makes your code look prettier:
if ( 1 > 2 > 3):
is totally samw with
if 1 > 2 > 3:
Most important part is, (1)
is not a tuple
with a single element. Those parenthesis are evaluated as grouper, and have no effect in execution so it is totally same with 1
. On the other hand, (1,)
is a tuple
and ,
after the first element implies that.
So
print ("Hello World")
print "Hello World"
are totally the same thing. But ('1','2')
is a tuple so print
statement prints it.
Upvotes: 1
Reputation: 8386
print ('Hello World')
prints the string Hello World
print ('1','2')
prints the tuple ('1','2')
.
Upvotes: 0