Operators
Arithmetic operations - exponential ** / Bitwise operator - XOR ^
# Exponential
n = 6**2 + 6
print(n)
# 42
# Bitwise XOR
n = 6^2
print(n)
# 4
# Division
n = 105 / 60
print(n)
# 1.74
# Floor Division
n = 105 // 60
print(n)
# 1
# Remainder example - with floor division
minutes = 105
hours = minutes // 60
remainder = minutes - hours*60
print(remainder)
#45
# Remainder example - with modulo
minutes = 105
remainder = 105 % 60
print(remainder)
# 45
Time
Convert GMT time since Unix time.
# The time module provides a function ...
# that returns the current GMT in “the epoch”
#
# Let's write a function that returns ...
# days, hours, minutes, seconds since Unix birthday 01.01.1970
import time
today = time.time()
print(today)
# 1636720824.934335
def convert_GMT(t):
days = int(t) // (3600 * 4)
remainder = int(t) % (3600 * 4)
hours = remainder // 3600
remainder = remainder % 3600
minutes = remainder // 60
remainder = remainder % 60
seconds = remainder
return (
str(days) + " days " + \
str(hours) + " hours " + \
str(minutes) + " minutes " + \
str(seconds) + " seconds"
)
print(convert_GMT(today))
# 113661 days 0 hours 50 minutes 32 seconds