1

I am attempting to code in Python (recently getting back into it). I want to use the def keyword. But it doesn't seem to work. I am using Python 2.7.5: The code is

def main():
    print "This is a test"

And the IDLE console shows it as:

>>> ================================ RESTART ================================
>>> 
>>> 

Keep in mind, that if I remove the whole def command completely, the statements will work. Any insight on this?

1
  • Add main() after the function definition to call the function. Commented Sep 2, 2013 at 18:56

2 Answers 2

1

You need to call the main function after that.

Ex.

def main():
    print "This is a test."
main()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Forgot about calling the function. :/
1

You need to call the function. See below:

>>> def main():
...     print "This is a test"
...
>>> main() #Call the function
This is a test
>>>

2 Comments

The code was properly indented, it was just due to the fact of trying to format the code proerply. And thanks! Completely forgot about calling the function. >_> Guess that;s what happens when you don't care in Python for a few months.
Ok. I removed the indentation part of my post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.