Question about def in Input!


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/0/3?curriculum_id=4f89dab3d788890003000096#

File "python", line 5
def original = raw_input()
^
SyntaxError: invalid syntax

I was wondering why can't i use def original = raw_input() here. In which cases should i use def variable?
However, if i removed def like the 2nd image below the code works. So my codes becomes original=raw_input()


<img src="//codecademy-discourse.s3.amazonaws.com/original/5X/8/8/b/5/88b5ce0be62532f610f0fec0d4db11fd23584e24.JPG" width="690" height="343">

Code works when i remove def

<img src="//codecademy-discourse.s3.amazonaws.com/original/5X/a/c/8/1/ac810849048cac91029e475c13cc7ad8a86493b1.JPG" width="690" height="340">


#2

original is a variable that is intended to reference a string object, the output of raw_input() that is stored in memory. It will be the user input.

def is only used to define a function. For this exercise we are not going to define any functions, so put that desire aside and set out to write inline code in the global namespace. No functions are expected by the lesson checker. Only executable code that runs from start to finish.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.