time method python code example
Example 1: python: measure time code
import time
def power_two(my_range):
return [x**2 for x in range(my_range)]
def measure_time(func):
start = time.time()
func()
end = time.time()
print(end - start)
measure_time(lambda: power_two(10000000))
Example 2: python clock
import datetime
import time
def clock():
while True:
print(datetime.datetime.now().strftime("%H:%M:%S"), end="\r")
time.sleep(1)
clock()
Example 3: python time seconds
import time
seconds = 1545925769.9618232
local_time = time.ctime(seconds)
print("Local time:", local_time)