Print and input functions


#1

In the lesson we use print without a parenthesis. When I tried it on my own editor I received an error that I was missing the parenthesis. Do later versions of Python require parenthesis?
Also, could I use the input() function instead of the raw_input() function as I was receiving an error message when when I entered raw_input() into my editor?


#2

You have to use the correct format for the different versions, in python 3.* print was changed to a built-in function.

In Python 2.*

print "Anything"

In Python 3.*

print("Anything")

#3

Thanks! Is that the same for input()?


#4

Yes,

Python 3.*

input("STUFF")

Python 2.*

raw_input("STUFF")

As a note:

Python 2.* does have an input function built in, it is something like eval() but it does so to the users input. Meaning that it can be very bad.

Example:

a = input("Input something:")

The user does some fancy stuff

# Prompt: Input something:
exit()

As you can see easily it can end badly.