0

I am using VS studios, using python. When I try to create a function, I constantly keep getting a syntax error. I am not sure why?

 def sayhi():
 print("Hello User")
sayhi()
2
  • Can you please format your code as most issues in python are tabbing issues, it's very difficult to troubleshoot when you don't have it in a code block. Commented Apr 29, 2020 at 13:29
  • 3
    The def sayhi() has a bad indentation Commented Apr 29, 2020 at 13:32

2 Answers 2

1

Your function should have correct indentation like so:

def sayhi():
 print('Hello User')
sayhi()

Otherwise python will throw a fit as indentation is very important to python and its functions, classes, etc.

The issue in your code is the space before def sayhi(): which is going to throw an IndentationError without a doubt, remove that space and you should be much better off

answered Apr 29, 2020 at 13:30
Sign up to request clarification or add additional context in comments.

2 Comments

It is indented properly but i keep getting an error. File "<stdin>", line 1 SyntaxError: invalid syntax
Then please ensure you have posted your code exactly as it is in your IDE/editor/whatever it may be.
0

do it in jupyter notebook on Visual Studio and you won't have any problems. Just make sure you're on the python interpreter

answered Nov 15, 2022 at 23:40

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.