Python contd
Operators
-
Refer Here for operators and Refer Here for operator precendence
-
Project euler 5
def lcm(start:int =1, end:int =10) -> int:
"""Lcm of a sequence
Args:
start (int, optional): start value. Defaults to 1.
end (int, optional): end value. Defaults to 10.
Returns:
int: lcm
"""
factor = end * (end -1)
max = factorial(end)
result = 0
# check if factor is divisible by all numbers in a sequence
# if not increment by factor
while factor <= max:
index = start
is_lcm = True
while index <= end:
if factor % index !=0:
is_lcm = False
break
index += 1
if is_lcm:
result = factor
break
factor += end * (end -1)
return result
How Python deals with allocating memory
- Python has two datatypes
- mutable: values can be changed without allocating new memory location
- immutable: every value change leads to a new memory location.
- int,float,complex are immutable.
- list is mutable
