time.sleep() vs time.gmtime()
time.sleep() and time.gmtime() are both Python Time Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. time.sleep(): Suspends execution for the given number of seconds (may be fractional). Its syntax is time.sleep(secs), and it returns none time.gmtime(): Converts a timestamp to a time.struct_time in UTC. Its syntax is time.gmtime(secs=None), and it returns struct time (UTC) Example of time.sleep(): print("Start")
time.sleep(2.5)
print("After 2.5 seconds"). Example of time.gmtime(): t = time.gmtime()
print(t.tm_year, t.tm_mon, t.tm_mday). Read the full references for time.sleep() and time.gmtime() to see parameters, edge cases, and example code side by side. Other Time Module APIs worth comparing: time.time(), time.localtime(), time.strftime(), time.strptime(), time.perf_counter(), time.monotonic(). Both belong to the Time Module category in the Python Reference documentation. Try both in the Python playground to see the behavioral difference live.