Guide Python Beginner

4.20 Interview Questions

Frequently asked Python syntax interview questions and practical coding exercises, covering keywords, identifiers, indentation, input/output, and the __main__ guard.

2 min read

Frequently Asked Syntax Questions

  • What is the difference between a keyword and an identifier?
  • Why does Python use indentation instead of braces?
  • What is the difference between a SyntaxError and a NameError?
  • Can you reassign a value to a name written in UPPER_CASE? Why or why not?
  • What does input() return, and why does that matter for arithmetic?
  • What is the purpose of if __name__ == "__main__":?

Practical Coding Questions

  • Write a function with a docstring and demonstrate retrieving it with help().
  • Fix this snippet’s IndentationError:
    if True:
    print("hi")
    
  • Show two different ways to continue a long expression across multiple lines.
  • Given a list of numeric strings from input(), write code that sums them as integers.
  • Identify and fix the missing colon in a given faulty function definition.

Quick Interview Answer

“The syntax topics that come up most in interviews are: why Python uses indentation instead of braces (it’s the block-delimiting syntax, not a style choice), the difference between a keyword and an identifier, why SyntaxError is caught before any code runs while NameError is a runtime error, why input() always returns a str, and what if __name__ == '__main__': actually does — letting a file work both as a script and as an importable module.”

Common Mistakes

  • Answering “Python doesn’t have syntax errors, just runtime errors” — conflating the two error categories is one of the fastest ways to lose credibility on a syntax question.
  • Not being able to explain why if __name__ == "__main__": matters, only that “you’re supposed to write it” — interviewers usually follow up asking what breaks without it.

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form