Basics
Comments
Text written in a program but not run by the computer is called a comment. Python interprets anything after a #
as a comment. Comments can:
Help other people reading the code understand it faster:
Ignore a line of code and see how a program will run without it:
Print
The print()
function is used to output text, numbers, or other printable information to the console.
Errors
The Python interpreter will report errors present in your code. For most error cases, the interpreter will display the line of code where the error was detected and place a caret character ^
under the portion of the code where the error was detected.
Python SyntaxError
A SyntaxError is reported by the Python interpreter when some portion of the code is incorrect. This can include misspelled keywords, missing or too many brackets or parenthesis, incorrect operators, missing or too many quotation marks, or other conditions.
Python NameError
A NameError is reported by the Python interpreter when it detects a variable that is unknown. This can occur when a variable is used before it has been assigned a value or if a variable name is spelled differently than the point at which it was defined. The Python interpreter will display the line of code where the NameError was detected and indicate which name it found that was not defined.
ZeroDivisionError
A ZeroDivisionError is reported by the Python interpreter when it detects a division operation is being performed and the denominator (bottom number) is 0. In mathematics, dividing a number by zero has no defined value, so Python treats this as an error condition and will report a ZeroDivisionError and display the line of code where the division occurred. This can also happen if a variable is used as the denominator and its value has been set to or changed to 0.
IndexError
Selecting an element that does not exist produces an IndexError
.
Working Directory
Last updated
Was this helpful?