1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Why do we write comments?
To explain code and make it easier for humans to read.
How do we write comments?
Use # in Python to write a single-line comment.
What is a variable?
A named storage location that holds a value.
How do we format a variable to indicate that it is a constant?
Write the variable name in ALL CAPS.
Why is it useful to declare some variables as constants?
It makes the code clearer and prevents accidental changes.
What does this symbol (+) do when between two numbers?
It adds the numbers.
What does this symbol (+) do when between two strings?
It concatenates (joins) the strings.
What does this symbol (+) do when between a number and a string?
It causes an error because you can't add them directly.
What does the following code do: print("My favorite number is ", end='') print(9)
It prints My favorite number is 9 on one line without a space after the first part.
What does the following code do: print("It is\nnice to\nsee you.")
It prints text on multiple lines: "It is" / "nice to" / "see you."
What does * do when applied to a string?
It repeats the string that many times.
What does str() do? When might you use it?
It converts data into a string. Use it when printing numbers with text.
What do int() and float() do? When might you use them?
int() converts to an integer, float() converts to a decimal. Use them for math operations.
What does the comma do in console output?
It separates items and adds a space between them when printed.
What does type() do?
It shows the data type of a value or variable.
What is the syntax for the input function?
input("Prompt message: ")
The randint() method - how does it work?
It returns a random integer between two specified numbers (inclusive).