Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am new to  Python and can't even write the first example:

print 'SyntaxError: invalid syntax'

this gives SyntaxError: invalid syntax

Why is this? I'm using version 3.1

1 Answer

0 votes
by (36.8k points)
edited by

Add the parenthesis, like this:

print()

Example of probably for the older python 2, which didn't use parenthesis for print.

Reasons are that in python 2.x print is a keyword, whereas in python >3 it's a function.

For beginners, that is the biggest difference between versions 2 and 3 (the next is raw_input. For python 3 use input instead). So you can probably keep going with the examples, just remember to add the parenthesis for print. Once you start printing arguments, put them inside parenthesis like this:

# The old python 2 way:

print "arg1", "arg2"

# The new python 3 way:

print("arg1", "arg2")

 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...