lists all the math operators in Python.
-2
and 30
, for example, are said to be integer values. The integer (or int) data type indicates values that are whole numbers. Numbers with a decimal point, such as 3.14
, are called floating-point numbers (or floats). Note that even though the value 42
is an integer, the value 42.0
would be a floating-point number.If you ever see the error message SyntaxError: EOL while scanning string literal
, you probably forgot the final single quote character at the end of the string, such as in this example:
str()
, int()
, and float()
functions.)The *
operator is used for multiplication when it operates on two integer or floating-point values. But when the *
operator is used on one string value and one integer value, it becomes the string replication operator. Enter a string multiplied by a number into the interactive shell to see this in action.
spam
variable in this example stores 'Hello'
until you replace it with 'Goodbye'
.It can be only one word.
It can use only letters, numbers, and the underscore (_
) character.
It can’t begin with a number.
Q: | 1. Which of the following are operators, and which are values? * 'hello' -88.8 - / + 5 |
Q: | 2. Which of the following is a variable, and which is a string? spam 'spam' |
Q: | 3. Name three data types. |
Q: | 4. What is an expression made up of? What do all expressions do? |
Q: | 5. This chapter introduced assignment statements, like |
Q: | 6. What does the variable bacon = 20 bacon + 1 |
Q: | 7. What should the following two expressions evaluate to? 'spam' + 'spamspam' 'spam' * 3 |
Q: | 8. Why is |
Q: | 9. What three functions can be used to get the integer, floating-point number, or string version of a value? |
Q: | 10. Why does this expression cause an error? How can you fix it? 'I have eaten ' + 99 + ' burritos.' Extra credit: Search online for the Python documentation for the |