-
Notifications
You must be signed in to change notification settings - Fork 0
/
time module.py
44 lines (30 loc) · 1.06 KB
/
time module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
# # # Time module
# # time module get the time duration taken to reach that perticular time function
initial1 = time.time()
count = 0
while count<51:
print(count)
time.sleep(2) # --------> here sleep method of time module is used
count+=1
print(f"Time taken by while loop: {time.time()-initial1}s")
# t1 = time.time() # -----> time method in time module
# for i in range(51):
# print(i)
# print(f"Time taken by for loop: {time.time()-t1}s")
# # More Methods of Time Module
# 1. ascttime, localtime, time
# i) ascttime
# ascttime method takes time in tuple format and convert it into string format
# ii) localtime
# localtime gives local time in tuple format
# iii) time
# time method of time module gives number of ticks
# iv) sleep method
# sleep method used when we want to wait the programe for specific time period
# How to get local time of pc in a string representable format
localtime = time.asctime(time.localtime(time.time()))
print(localtime)
# How to use sleep method
time.sleep(2)
#