5 + 7
12
20 - 8
12
30 * 50
1500
2500 / 500
5.0
2500 // 501
4
2 ** 8
256
30 % 7
2
2 + 6 * 8
50
(2 + 6) * 8
64
8.6 * 1.23456789
10.617283853999998
8.6 ** 123
8.776260445878955e+114
import math
Alternatively, use the following to avoid specifying the library in the function
from math import *
math.log(26 + 3)
3.367295829986474
math.sqrt(123)
11.090536506409418
# log base 2
math.log(4,2)
2.0
math.exp(10)
22026.465794806718
math.pow(2,8)
256.0
math.factorial(6)
720
# convert degrees to radians first
round(math.sin(math.radians(30)),2)
0.5
dir(math)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp']
print(math.log.__doc__)
log(x, [base=math.e]) Return the logarithm of x to the given base. If the base not specified, returns the natural logarithm (base e) of x.
help(math.sqrt)
Help on built-in function sqrt in module math: sqrt(x, /) Return the square root of x.
type(666)
int
type(666.666)
float
type("666")
str
print("hello jedi")
hello jedi
len("yeoda")
5
"I am a" + " " + "jedi master" + "!!"
'I am a jedi master!!'
"force" * 3
'forceforceforce'
"6" * 3
'666'
print("may", "the", "force", "be", "you")
may the force be you
print("may", "the", "force", "be", "you", sep = ",")
may,the,force,be,you
print("may the force")
print("be with you")
may the force be with you
True == True
True
False == False
True
True == False
False
False == True
False
True != False
True
False != True
True
not False
True
not True
False
True and True
True
False and False
False
True and False
False
False and True
False
True or True
True
False or False
False
True or False
True
False or True
True
float(5)
5.0
str(888)
'888'
int(5.789)
5
round(3.142,2)
3.14
me = "jedi"
me
'jedi'
x = 5
y = 10
x * y
50
a, b = 10, 20
a * b
200
you = input("What are you? ")
print("Hello " + you.capitalize() + "!")
What are you? Jedi Hello Jedi!
drink = input("What would you like to drink? ")
print("I want", drink)
What would you like to drink? root beer I want root beer
print(drink.capitalize(), "is the best beer on the planet!")
Root beer is the best beer on the planet!
drinks = input("How many drinks did you have? ").strip()
drinks10 = int(drinks) + 10
print("You probably drank " + str(drinks10) + ".")
How many drinks did you have? 6 You probably drank 16.
answer = input("Are we done yet? ")
print(answer, "we are done " + ":-)")
Are we done yet? Yes Yes we are done :-)