About this question
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
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
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Python Expert
Answered on Jun 7, 2021
To solve invalid syntax python print you should add the parenthesis, like this:
print()Example is probably for the older python 2, which didn't use parentheses 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 parentheses 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")
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Python interview questions, answered
Guides, tips and career advice on Python from JanBask experts.
Python How to Become a Python Developer: A Step-by-Step Guide for Beginners
Discover how to become a Python Developer via a practical 7-step guide build projects, maintain clean code, practice daily, and…
Python PCEP Certification Guide: Entry-Level Python Programmer Certification
Explore this PCEP certification guide for insights on cost, exam format, passing score, application, training, and study tips.…
Python Top 50+ Python Projects ideas for Beginners to Advanced
Discover innovative Python project ideas, explore advanced Python projects, and find good Python projects for beginners and…
Python How To Comment Out Multiple Lines In Python Like A Pro
Commenting out code is a common practice among programmers. It allows you to temporarily disable parts of your code without…