Mar-10-2018, 04:27 PM
print("Hello");prints "Hello"
but
print("Hello",3);prints ('Hello',3)
what happens when we use two arguments like above in print function ? why it prints ('Hello',3)?
print("Hello");prints "Hello"
print("Hello",3);prints ('Hello',3)
print
is a statement, not a function.("Hello")
to it, which is the same as "Hello"
(just in parentheses).("Hello", 3)
to it, which is a tuple.;
is unnecessary and ugly. (Mar-10-2018, 04:52 PM)stranac Wrote: [ -> ]In python 2, print
is a statement, not a function.
Quote:In the second code, you're passing ("Hello", 3)
to it, which is a tuple.
(Mar-11-2018, 03:45 AM)volcano Wrote: [ -> ]I'm using python 3.4. What is print in Python 3.4 ? statement or function ?In all python 3 versions is print a function.
(Mar-10-2018, 04:27 PM)volcano Wrote: [ -> ]why it prints ('Hello',3)?Because you use Python 2.
# Python 2.7 >>> print("Hello", 3) ('Hello', 3) # Python 3.6 >>> print('hello', 3) hello 3You should use Python 3.6.
>>> help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream. # Example want to keep comma >>> print('hello', 3, sep=',') hello,3