1. Exponentiation
All that math can be done on a calculator, so why use Python? Because you can combine math with other data types (e.g. booleans) and commands to create useful programs. Calculators just stick to numbers.
Now let's work with exponents.
eight = 2 ** 3
In the above example, we create a new variable called eight
and set it to 8
, or the result of 2 to the power to 3 (2^3).
Notice that we use **
instead of *
or the multiplication operator.
2. Bringing It All Together
Nice work! So far, you've learned about:
- Variables, which store values for later use
- Data types, such as numbers and booleans
- Whitespace, which separates statements
- Comments, which make your code easier to read
- Arithmetic operations, including
+
,-
,*
,/
,**
, and%
Instructions
Let's put our knowledge to work.
- Write a single-line comment on line 1. It can be anything! (Make sure it starts with
#
) - Set the variable
monty
equal toTrue
. - Set another variable
python
equal to1.234
. - Set a third variable
monty_python
equal topython
squared.
'Python' 카테고리의 다른 글
Pythons #3 예외처리 (0) | 2014.10.10 |
---|