Why is print function working without parentheses as shown in the Codecademy video?

Analyse data with Python - NumPi syntax - Betty’s Bakery exercise

Link to exercise: https://www.codecademy.com/paths/analyze-data-with-python/tracks/ida-3-introduction-to-numpy/modules/ida-3-1-numpy-syntax/projects/betty-bakery

Link to Codecademy video: Numpy Project: Betty's Bakery - YouTube

Hi everyone,
a very beginner here.

Until now I’ve always seen print as a function, so with the syntax “print()”.

Often, in the previous exercises, I forgot the parentheses, getting an error.

Why in this exercise and in the linked walkthrough video, at line 10, print without parentheses does not give an error?

Am I missing something?

Thank you very much in advance,
Dario

It appears the video is an older one, and the user is writing in Python 2. Before Python 3 print was actually a statement and not a function, which is why there is no error in the video. So the output for this:

print 'Hello World'
# Python 2 print STATEMENT

is the same as the output for this:

print('Hello World')
# Python 3 print FUNCTION

Since the course is now for Python 3, you need to use print as a function rather than a statement.


Thanks for pointing this out, I’m actually gonna ask about the video being updated. :slightly_smiling_face:

2 Likes

Thank you very much. Now everything is clear and at its place :slight_smile:

Dario

1 Like