Which way of splitting a long statement over several lines does PEP 8 prefer?
Inside (), [] or {} a statement may run over many lines with no extra symbol. A trailing backslash also works but breaks easily if a space follows it.
Python Basics and Syntax · Exercise 1 of 4
Fifteen multiple-choice questions on Python basics: how CPython runs code, indentation, comments, docstrings, identifiers and keywords, print() and input(), and the main guard. Pick an option to check your answer instantly.
Which way of splitting a long statement over several lines does PEP 8 prefer?
Inside (), [] or {} a statement may run over many lines with no extra symbol. A trailing backslash also works but breaks easily if a space follows it.
What does the pass statement do?
pass lets you write an empty function, class or block (def todo(): pass) without an IndentationError. Use continue, break or return for the other jobs.
Which statement about Python is false?
Python is dynamically typed: names are not declared and carry no type. The objects they refer to do have types, and Python will not silently mix them (strong typing).
Which character lets you write several simple statements on one line, as in a = 1 ? b = 2?
a = 1; b = 2 is legal Python, though PEP 8 discourages it. A comma would build a tuple; a colon starts a block.
Line 1 of a script prints "Start" and line 50 has a missing closing bracket. What happens when you run it?
The whole file is compiled to bytecode before execution starts, so syntax errors stop it before line 1 runs. Runtime errors such as NameError, in contrast, appear only when the faulty line is reached.
Timed online tests with instant scores and explanations.