Learning the language Python
Operators | Symbol | Example | Output |
---|---|---|---|
Addition | + | 1 + 2 |
3 |
Subtraction | - | 10 - 3 |
7 |
Multiplication | * | 3 * 4 |
12 |
Division | / | 13 / 7 |
1.8571428571428572 |
Residue | % | 20 % 3 |
2 |
Exponents | ** | 2**8 |
256 |
To solve other mathematical calculations such as: square root, round, logarithms, etc. The math library must be imported.
import math
# Square root
math.sqrt(9)
# Round
math.ceil(1.739)
It is defined using single and double quotes.
'Polar bears live in "antarctica"'
"The city of 'Cusco' is majestic"
In a string you can include special characters(\t
, \n
, etc.)
Print: function to display data in the terminal.
print('Hello\nworld')
Hello
world
it can also define a string in multiple lines and include special characters with: """
"""
universe
Earth
plants animals
"""
This is stored as:
'\nuniverse\n\tearth\n\t\tplants\tanimals'
The result on the screen with print
is:
universe
Earth
plants animals
Can addition and multiply strings using symbols: +
and *
.
# Addition
'Pacific' + 'ocean'
# output
'Pacific ocean'
# Multiply
'Hi!'*3
# output
'Hi!Hi!Hi!'
Escape the special characters use: \
.
print('Hello\\nworld')
# output
'Hello\nworld'
Store the raw string it can use: r
.
print(r'\route\tasks\new')
# output
'\route\tasks\new'