Function Junction


#1



Replace this line with your code.

Instructions
Go ahead and create a function, spam, that prints the string "Eggs!" to the console. Don't forget to include a comment of your own choosing (enclose it in triple quotes!).

Why does print have to have a space . If i place print directly under def it comes out wrong.
Can some please explain please. Does this have to do with what was taught earlier whitespaces?


#2

Yup, it sure does.
Since Python doesn't use curly braces for holding functions and such (except for dictionaries), it uses whitespace. This shows and tells Python that anything indented under your function and/or if/elif/else statements, is what belongs to it and what is executed when called. Does this help?


#3

it is indentation since there is a colon


#4

So in other words not command can go under def
is that pretty much it?
Thanks for the help


#5

Do you mean the not operator? Yes, if it's going to be in something (like a operation, or statement and such). You cant write not by itself, it won't work and it will throw an error.

Check these links out on whitespace/indentation:

https://docs.python.org/2.0/ref/indentation.html


#6

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