Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function does not print expected result [closed]

def white():
    print
print ("First line")
white()
print ("Second line")

This is one of my first scripts. When I press the "F5" key, this is the result:

First line
Second line

Where is the mistake?

like image 819
user3207246 Avatar asked Feb 16 '26 04:02

user3207246


1 Answers

You are using Python 3 in which print is a function. In Python 2 print is a statement and your code would behave as you expect.

This line:

print

does not call the function. It merely looks up the name print. And that does not result in anything being place on the output device.

You presumably meant to write something like this that actually calls the function:

def white():
    print()

print ("First line")
white()
print ("Second line")

Output

First line

Second line
like image 169
David Heffernan Avatar answered Feb 18 '26 18:02

David Heffernan