Python Syntax Flashcards
What symbol tells Python to interpret the following as a comment?
#
What function tells a computer to talk?
print()
The message should be surrounded by “ “ or ‘ ‘
Be consistent with whichever chosen
What are the printed words as a result of the print() function referred to as?
Output
What are blocks of text called?
Strings
Does it matter which kind of quotation is used for a string?
No, either “” or ‘’
Just be consistent with whichever chosen.
How do you assign variables?
By using the equal sign (=)
message_string = “Hello there” # Prints “Hello there” print(message_string)
Can variables start with numbers?
No, but they can have numbers after the first letter.
Can variables have spaces or symbols other than an underscore ( _ )?
No
What does Python refer to mistakes as?
Errors.
It will point to the location where an error occurred with a ^ character.
What are two common errors encountered while writing Python?
SyntaxError
NameError
What does SyntaxError mean?
There is something wrong with the way your program is written
- punctuation that does not belong, a command where it is not expected, or a missing parentheses can all trigger SyntaxError.
When does a NameError occur?
When the Python interpreter sees a word it does not recognize.
Code that contains something that looks like a variable but was never defined will throw a NameError.
Or when the quotes are never used but should have been.
What does a SyntaxError: EOL mean?
A string wasn’t closed, or wasn’t closed with the same quote-character that started it.
What is the modulo operator?
A companion to division.
It is indicated by % and returns the remainder after division is performed.
What is a float?
A number with a decimal point.
You can define a float with numbers after the decimal point or by just including a decimal point at the end.
You can also define a float using scientific notation, with e indicating the power of 10.