[{"data":1,"prerenderedAt":1360},["ShallowReactive",2],{"doc-\u002Fstandard-library\u002Ftime.sleep-function-explained":3},{"id":4,"title":5,"body":6,"description":1353,"extension":1354,"meta":1355,"navigation":79,"path":1356,"seo":1357,"stem":1358,"__hash__":1359},"content\u002Fstandard-library\u002Ftime.sleep-function-explained.md","time.sleep() Function Explained",{"type":7,"value":8,"toc":1324},"minimark",[9,13,21,24,40,47,52,141,154,158,163,166,192,201,205,208,228,234,237,251,254,299,303,306,366,369,377,385,389,394,397,408,411,505,508,525,532,536,541,546,549,593,597,600,644,648,654,698,702,705,708,741,745,750,754,761,780,786,789,818,825,829,834,867,873,875,903,906,979,983,988,1013,1019,1047,1050,1096,1106,1110,1115,1118,1129,1135,1139,1144,1147,1161,1164,1168,1173,1176,1187,1190,1194,1198,1203,1207,1210,1214,1219,1223,1226,1229,1254,1257,1282,1286,1289,1293,1320],[10,11,5],"h1",{"id":12},"timesleep-function-explained",[14,15,16,20],"p",{},[17,18,19],"code",{},"time.sleep()"," pauses a Python program for a set amount of time.",[14,22,23],{},"It is a simple and useful function for:",[25,26,27,31,34,37],"ul",{},[28,29,30],"li",{},"adding a delay in a script",[28,32,33],{},"building a basic countdown",[28,35,36],{},"spacing out repeated output",[28,38,39],{},"practicing program flow",[14,41,42,43,46],{},"This function is part of Python’s ",[17,44,45],{},"time"," module, so you must import that module before using it.",[48,49,51],"h2",{"id":50},"quick-example","Quick example",[53,54,59],"pre",{"className":55,"code":56,"language":57,"meta":58,"style":58},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import time\n\nprint(\"Start\")\ntime.sleep(2)\nprint(\"After 2 seconds\")\n","python","",[17,60,61,74,81,105,125],{"__ignoreMap":58},[62,63,66,70],"span",{"class":64,"line":65},"line",1,[62,67,69],{"class":68},"sVHd0","import",[62,71,73],{"class":72},"su5hD"," time\n",[62,75,77],{"class":64,"line":76},2,[62,78,80],{"emptyLinePlaceholder":79},true,"\n",[62,82,84,88,92,96,100,102],{"class":64,"line":83},3,[62,85,87],{"class":86},"sptTA","print",[62,89,91],{"class":90},"sP7_E","(",[62,93,95],{"class":94},"sjJ54","\"",[62,97,99],{"class":98},"s_sjI","Start",[62,101,95],{"class":94},[62,103,104],{"class":90},")\n",[62,106,108,110,113,117,119,123],{"class":64,"line":107},4,[62,109,45],{"class":72},[62,111,112],{"class":90},".",[62,114,116],{"class":115},"slqww","sleep",[62,118,91],{"class":90},[62,120,122],{"class":121},"srdBf","2",[62,124,104],{"class":90},[62,126,128,130,132,134,137,139],{"class":64,"line":127},5,[62,129,87],{"class":86},[62,131,91],{"class":90},[62,133,95],{"class":94},[62,135,136],{"class":98},"After 2 seconds",[62,138,95],{"class":94},[62,140,104],{"class":90},[14,142,143,144,147,148,150,151,112],{},"Use ",[17,145,146],{},"time.sleep(seconds)"," to pause the program. The value can be an integer like ",[17,149,122],{}," or a decimal like ",[17,152,153],{},"0.5",[48,155,157],{"id":156},"what-timesleep-does","What time.sleep() does",[14,159,160,162],{},[17,161,19],{}," stops your program for a number of seconds.",[14,164,165],{},"Key points:",[25,167,168,171,177,184],{},[28,169,170],{},"It pauses program execution.",[28,172,173,174,176],{},"It belongs to the built-in ",[17,175,45],{}," module.",[28,178,179,180,183],{},"You must write ",[17,181,182],{},"import time"," before using it.",[28,185,186,187,189,190,112],{},"It accepts whole numbers like ",[17,188,122],{}," and decimal numbers like ",[17,191,153],{},[14,193,194,195,200],{},"If you are new to modules, see ",[196,197,199],"a",{"href":198},"\u002Flearn\u002Fpython-modules-explained","Python modules explained"," first.",[48,202,204],{"id":203},"basic-syntax","Basic syntax",[14,206,207],{},"The basic syntax is:",[53,209,211],{"className":55,"code":210,"language":57,"meta":58,"style":58},"time.sleep(seconds)\n",[17,212,213],{"__ignoreMap":58},[62,214,215,217,219,221,223,226],{"class":64,"line":65},[62,216,45],{"class":72},[62,218,112],{"class":90},[62,220,116],{"class":115},[62,222,91],{"class":90},[62,224,225],{"class":115},"seconds",[62,227,104],{"class":90},[14,229,230,231,233],{},"Here, ",[17,232,225],{}," is the length of the pause.",[14,235,236],{},"Examples:",[25,238,239,245],{},[28,240,241,244],{},[17,242,243],{},"time.sleep(1)"," pauses for about one second",[28,246,247,250],{},[17,248,249],{},"time.sleep(0.25)"," pauses for about a quarter of a second",[14,252,253],{},"A full example:",[53,255,257],{"className":55,"code":256,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(1)\nprint(\"Done waiting\")\n",[17,258,259,265,269,284],{"__ignoreMap":58},[62,260,261,263],{"class":64,"line":65},[62,262,69],{"class":68},[62,264,73],{"class":72},[62,266,267],{"class":64,"line":76},[62,268,80],{"emptyLinePlaceholder":79},[62,270,271,273,275,277,279,282],{"class":64,"line":83},[62,272,45],{"class":72},[62,274,112],{"class":90},[62,276,116],{"class":115},[62,278,91],{"class":90},[62,280,281],{"class":121},"1",[62,283,104],{"class":90},[62,285,286,288,290,292,295,297],{"class":64,"line":107},[62,287,87],{"class":86},[62,289,91],{"class":90},[62,291,95],{"class":94},[62,293,294],{"class":98},"Done waiting",[62,296,95],{"class":94},[62,298,104],{"class":90},[48,300,302],{"id":301},"simple-example","Simple example",[14,304,305],{},"This example prints one message, waits, and then prints another message:",[53,307,309],{"className":55,"code":308,"language":57,"meta":58,"style":58},"import time\n\nprint(\"Before pause\")\ntime.sleep(3)\nprint(\"After pause\")\n",[17,310,311,317,321,336,351],{"__ignoreMap":58},[62,312,313,315],{"class":64,"line":65},[62,314,69],{"class":68},[62,316,73],{"class":72},[62,318,319],{"class":64,"line":76},[62,320,80],{"emptyLinePlaceholder":79},[62,322,323,325,327,329,332,334],{"class":64,"line":83},[62,324,87],{"class":86},[62,326,91],{"class":90},[62,328,95],{"class":94},[62,330,331],{"class":98},"Before pause",[62,333,95],{"class":94},[62,335,104],{"class":90},[62,337,338,340,342,344,346,349],{"class":64,"line":107},[62,339,45],{"class":72},[62,341,112],{"class":90},[62,343,116],{"class":115},[62,345,91],{"class":90},[62,347,348],{"class":121},"3",[62,350,104],{"class":90},[62,352,353,355,357,359,362,364],{"class":64,"line":127},[62,354,87],{"class":86},[62,356,91],{"class":90},[62,358,95],{"class":94},[62,360,361],{"class":98},"After pause",[62,363,95],{"class":94},[62,365,104],{"class":90},[14,367,368],{},"Expected output order:",[53,370,375],{"className":371,"code":373,"language":374,"meta":58},[372],"language-text","Before pause\nAfter pause\n","text",[17,376,373],{"__ignoreMap":58},[14,378,379,380,382,383,112],{},"You will see ",[17,381,331],{}," first. Then the program waits about 3 seconds. After that, it prints ",[17,384,361],{},[48,386,388],{"id":387},"using-timesleep-in-a-loop","Using time.sleep() in a loop",[14,390,391,393],{},[17,392,19],{}," is often used inside loops.",[14,395,396],{},"This is useful for:",[25,398,399,402,405],{},[28,400,401],{},"countdowns",[28,403,404],{},"repeated messages",[28,406,407],{},"making output easier to follow",[14,409,410],{},"Example:",[53,412,414],{"className":55,"code":413,"language":57,"meta":58,"style":58},"import time\n\nfor i in range(3):\n    print(\"Loop number:\", i)\n    time.sleep(1)\n\nprint(\"Finished\")\n",[17,415,416,422,426,447,469,484,489],{"__ignoreMap":58},[62,417,418,420],{"class":64,"line":65},[62,419,69],{"class":68},[62,421,73],{"class":72},[62,423,424],{"class":64,"line":76},[62,425,80],{"emptyLinePlaceholder":79},[62,427,428,431,434,437,440,442,444],{"class":64,"line":83},[62,429,430],{"class":68},"for",[62,432,433],{"class":72}," i ",[62,435,436],{"class":68},"in",[62,438,439],{"class":86}," range",[62,441,91],{"class":90},[62,443,348],{"class":121},[62,445,446],{"class":90},"):\n",[62,448,449,452,454,456,459,461,464,467],{"class":64,"line":107},[62,450,451],{"class":86},"    print",[62,453,91],{"class":90},[62,455,95],{"class":94},[62,457,458],{"class":98},"Loop number:",[62,460,95],{"class":94},[62,462,463],{"class":90},",",[62,465,466],{"class":115}," i",[62,468,104],{"class":90},[62,470,471,474,476,478,480,482],{"class":64,"line":127},[62,472,473],{"class":72},"    time",[62,475,112],{"class":90},[62,477,116],{"class":115},[62,479,91],{"class":90},[62,481,281],{"class":121},[62,483,104],{"class":90},[62,485,487],{"class":64,"line":486},6,[62,488,80],{"emptyLinePlaceholder":79},[62,490,492,494,496,498,501,503],{"class":64,"line":491},7,[62,493,87],{"class":86},[62,495,91],{"class":90},[62,497,95],{"class":94},[62,499,500],{"class":98},"Finished",[62,502,95],{"class":94},[62,504,104],{"class":90},[14,506,507],{},"What happens:",[25,509,510,513,516,519],{},[28,511,512],{},"The loop prints a line.",[28,514,515],{},"The program pauses for 1 second.",[28,517,518],{},"The loop continues.",[28,520,521,522,524],{},"After the loop ends, ",[17,523,500],{}," is printed.",[14,526,527,528,112],{},"A beginner-friendly real use case is a countdown timer. For a complete example, see ",[196,529,531],{"href":530},"\u002Fexamples\u002Fpython-countdown-timer-example","Python countdown timer example",[48,533,535],{"id":534},"what-value-to-pass","What value to pass",[14,537,538,539,112],{},"You can pass different kinds of numbers to ",[17,540,19],{},[542,543,545],"h3",{"id":544},"full-seconds","Full seconds",[14,547,548],{},"Use an integer when you want a whole number of seconds:",[53,550,552],{"className":55,"code":551,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(2)\nprint(\"Waited 2 seconds\")\n",[17,553,554,560,564,578],{"__ignoreMap":58},[62,555,556,558],{"class":64,"line":65},[62,557,69],{"class":68},[62,559,73],{"class":72},[62,561,562],{"class":64,"line":76},[62,563,80],{"emptyLinePlaceholder":79},[62,565,566,568,570,572,574,576],{"class":64,"line":83},[62,567,45],{"class":72},[62,569,112],{"class":90},[62,571,116],{"class":115},[62,573,91],{"class":90},[62,575,122],{"class":121},[62,577,104],{"class":90},[62,579,580,582,584,586,589,591],{"class":64,"line":107},[62,581,87],{"class":86},[62,583,91],{"class":90},[62,585,95],{"class":94},[62,587,588],{"class":98},"Waited 2 seconds",[62,590,95],{"class":94},[62,592,104],{"class":90},[542,594,596],{"id":595},"fractional-seconds","Fractional seconds",[14,598,599],{},"Use a float when you want a shorter pause:",[53,601,603],{"className":55,"code":602,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(0.5)\nprint(\"Waited half a second\")\n",[17,604,605,611,615,629],{"__ignoreMap":58},[62,606,607,609],{"class":64,"line":65},[62,608,69],{"class":68},[62,610,73],{"class":72},[62,612,613],{"class":64,"line":76},[62,614,80],{"emptyLinePlaceholder":79},[62,616,617,619,621,623,625,627],{"class":64,"line":83},[62,618,45],{"class":72},[62,620,112],{"class":90},[62,622,116],{"class":115},[62,624,91],{"class":90},[62,626,153],{"class":121},[62,628,104],{"class":90},[62,630,631,633,635,637,640,642],{"class":64,"line":107},[62,632,87],{"class":86},[62,634,91],{"class":90},[62,636,95],{"class":94},[62,638,639],{"class":98},"Waited half a second",[62,641,95],{"class":94},[62,643,104],{"class":90},[542,645,647],{"id":646},"zero","Zero",[14,649,650,653],{},[17,651,652],{},"0"," is valid, but it usually creates no visible delay:",[53,655,657],{"className":55,"code":656,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(0)\nprint(\"No visible pause\")\n",[17,658,659,665,669,683],{"__ignoreMap":58},[62,660,661,663],{"class":64,"line":65},[62,662,69],{"class":68},[62,664,73],{"class":72},[62,666,667],{"class":64,"line":76},[62,668,80],{"emptyLinePlaceholder":79},[62,670,671,673,675,677,679,681],{"class":64,"line":83},[62,672,45],{"class":72},[62,674,112],{"class":90},[62,676,116],{"class":115},[62,678,91],{"class":90},[62,680,652],{"class":121},[62,682,104],{"class":90},[62,684,685,687,689,691,694,696],{"class":64,"line":107},[62,686,87],{"class":86},[62,688,91],{"class":90},[62,690,95],{"class":94},[62,692,693],{"class":98},"No visible pause",[62,695,95],{"class":94},[62,697,104],{"class":90},[542,699,701],{"id":700},"negative-numbers","Negative numbers",[14,703,704],{},"Negative numbers are not valid.",[14,706,707],{},"This will cause an error:",[53,709,711],{"className":55,"code":710,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(-1)\n",[17,712,713,719,723],{"__ignoreMap":58},[62,714,715,717],{"class":64,"line":65},[62,716,69],{"class":68},[62,718,73],{"class":72},[62,720,721],{"class":64,"line":76},[62,722,80],{"emptyLinePlaceholder":79},[62,724,725,727,729,731,733,737,739],{"class":64,"line":83},[62,726,45],{"class":72},[62,728,112],{"class":90},[62,730,116],{"class":115},[62,732,91],{"class":90},[62,734,736],{"class":735},"smGrS","-",[62,738,281],{"class":121},[62,740,104],{"class":90},[48,742,744],{"id":743},"common-errors-and-confusion","Common errors and confusion",[14,746,747,748,112],{},"Beginners often run into a few common problems with ",[17,749,19],{},[542,751,753],{"id":752},"forgetting-to-import-time","Forgetting to import time",[14,755,756,757,760],{},"This causes a ",[17,758,759],{},"NameError",":",[53,762,764],{"className":55,"code":763,"language":57,"meta":58,"style":58},"time.sleep(2)\n",[17,765,766],{"__ignoreMap":58},[62,767,768,770,772,774,776,778],{"class":64,"line":65},[62,769,45],{"class":72},[62,771,112],{"class":90},[62,773,116],{"class":115},[62,775,91],{"class":90},[62,777,122],{"class":121},[62,779,104],{"class":90},[14,781,782,783,785],{},"Python does not know what ",[17,784,45],{}," means unless you import it first.",[14,787,788],{},"Correct version:",[53,790,792],{"className":55,"code":791,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(2)\n",[17,793,794,800,804],{"__ignoreMap":58},[62,795,796,798],{"class":64,"line":65},[62,797,69],{"class":68},[62,799,73],{"class":72},[62,801,802],{"class":64,"line":76},[62,803,80],{"emptyLinePlaceholder":79},[62,805,806,808,810,812,814,816],{"class":64,"line":83},[62,807,45],{"class":72},[62,809,112],{"class":90},[62,811,116],{"class":115},[62,813,91],{"class":90},[62,815,122],{"class":121},[62,817,104],{"class":90},[14,819,820,821,112],{},"If you want help with this error, see ",[196,822,824],{"href":823},"\u002Ferrors\u002Fnameerror-name-is-not-defined-fix","NameError: name is not defined",[542,826,828],{"id":827},"passing-a-string-instead-of-a-number","Passing a string instead of a number",[14,830,756,831,760],{},[17,832,833],{},"TypeError",[53,835,837],{"className":55,"code":836,"language":57,"meta":58,"style":58},"import time\n\ntime.sleep(\"2\")\n",[17,838,839,845,849],{"__ignoreMap":58},[62,840,841,843],{"class":64,"line":65},[62,842,69],{"class":68},[62,844,73],{"class":72},[62,846,847],{"class":64,"line":76},[62,848,80],{"emptyLinePlaceholder":79},[62,850,851,853,855,857,859,861,863,865],{"class":64,"line":83},[62,852,45],{"class":72},[62,854,112],{"class":90},[62,856,116],{"class":115},[62,858,91],{"class":90},[62,860,95],{"class":94},[62,862,122],{"class":98},[62,864,95],{"class":94},[62,866,104],{"class":90},[14,868,869,872],{},[17,870,871],{},"\"2\""," is a string, not a number.",[14,874,788],{},[53,876,877],{"className":55,"code":791,"language":57,"meta":58,"style":58},[17,878,879,885,889],{"__ignoreMap":58},[62,880,881,883],{"class":64,"line":65},[62,882,69],{"class":68},[62,884,73],{"class":72},[62,886,887],{"class":64,"line":76},[62,888,80],{"emptyLinePlaceholder":79},[62,890,891,893,895,897,899,901],{"class":64,"line":83},[62,892,45],{"class":72},[62,894,112],{"class":90},[62,896,116],{"class":115},[62,898,91],{"class":90},[62,900,122],{"class":121},[62,902,104],{"class":90},[14,904,905],{},"You can also convert user input if needed:",[53,907,909],{"className":55,"code":908,"language":57,"meta":58,"style":58},"import time\n\nseconds = float(input(\"Enter seconds: \"))\ntime.sleep(seconds)\nprint(\"Done\")\n",[17,910,911,917,921,950,964],{"__ignoreMap":58},[62,912,913,915],{"class":64,"line":65},[62,914,69],{"class":68},[62,916,73],{"class":72},[62,918,919],{"class":64,"line":76},[62,920,80],{"emptyLinePlaceholder":79},[62,922,923,926,929,933,935,938,940,942,945,947],{"class":64,"line":83},[62,924,925],{"class":72},"seconds ",[62,927,928],{"class":735},"=",[62,930,932],{"class":931},"sZMiF"," float",[62,934,91],{"class":90},[62,936,937],{"class":86},"input",[62,939,91],{"class":90},[62,941,95],{"class":94},[62,943,944],{"class":98},"Enter seconds: ",[62,946,95],{"class":94},[62,948,949],{"class":90},"))\n",[62,951,952,954,956,958,960,962],{"class":64,"line":107},[62,953,45],{"class":72},[62,955,112],{"class":90},[62,957,116],{"class":115},[62,959,91],{"class":90},[62,961,225],{"class":115},[62,963,104],{"class":90},[62,965,966,968,970,972,975,977],{"class":64,"line":127},[62,967,87],{"class":86},[62,969,91],{"class":90},[62,971,95],{"class":94},[62,973,974],{"class":98},"Done",[62,976,95],{"class":94},[62,978,104],{"class":90},[542,980,982],{"id":981},"using-sleep-without-the-module-name","Using sleep() without the module name",[14,984,985,986,760],{},"This does not work if you only wrote ",[17,987,182],{},[53,989,991],{"className":55,"code":990,"language":57,"meta":58,"style":58},"import time\n\nsleep(2)\n",[17,992,993,999,1003],{"__ignoreMap":58},[62,994,995,997],{"class":64,"line":65},[62,996,69],{"class":68},[62,998,73],{"class":72},[62,1000,1001],{"class":64,"line":76},[62,1002,80],{"emptyLinePlaceholder":79},[62,1004,1005,1007,1009,1011],{"class":64,"line":83},[62,1006,116],{"class":115},[62,1008,91],{"class":90},[62,1010,122],{"class":121},[62,1012,104],{"class":90},[14,1014,1015,1016,1018],{},"With ",[17,1017,182],{},", you must write:",[53,1020,1021],{"className":55,"code":791,"language":57,"meta":58,"style":58},[17,1022,1023,1029,1033],{"__ignoreMap":58},[62,1024,1025,1027],{"class":64,"line":65},[62,1026,69],{"class":68},[62,1028,73],{"class":72},[62,1030,1031],{"class":64,"line":76},[62,1032,80],{"emptyLinePlaceholder":79},[62,1034,1035,1037,1039,1041,1043,1045],{"class":64,"line":83},[62,1036,45],{"class":72},[62,1038,112],{"class":90},[62,1040,116],{"class":115},[62,1042,91],{"class":90},[62,1044,122],{"class":121},[62,1046,104],{"class":90},[14,1048,1049],{},"Another valid option is:",[53,1051,1053],{"className":55,"code":1052,"language":57,"meta":58,"style":58},"from time import sleep\n\nsleep(2)\nprint(\"Done\")\n",[17,1054,1055,1068,1072,1082],{"__ignoreMap":58},[62,1056,1057,1060,1063,1065],{"class":64,"line":65},[62,1058,1059],{"class":68},"from",[62,1061,1062],{"class":72}," time ",[62,1064,69],{"class":68},[62,1066,1067],{"class":72}," sleep\n",[62,1069,1070],{"class":64,"line":76},[62,1071,80],{"emptyLinePlaceholder":79},[62,1073,1074,1076,1078,1080],{"class":64,"line":83},[62,1075,116],{"class":115},[62,1077,91],{"class":90},[62,1079,122],{"class":121},[62,1081,104],{"class":90},[62,1083,1084,1086,1088,1090,1092,1094],{"class":64,"line":107},[62,1085,87],{"class":86},[62,1087,91],{"class":90},[62,1089,95],{"class":94},[62,1091,974],{"class":98},[62,1093,95],{"class":94},[62,1095,104],{"class":90},[14,1097,1098,1099,1101,1102,1105],{},"For beginners, ",[17,1100,182],{}," and ",[17,1103,1104],{},"time.sleep(...)"," is usually clearer.",[542,1107,1109],{"id":1108},"expecting-exact-timing","Expecting exact timing",[14,1111,1112,1114],{},[17,1113,19],{}," usually waits about the amount of time you requested, but it is not perfectly exact.",[14,1116,1117],{},"Small timing differences can happen because of:",[25,1119,1120,1123,1126],{},[28,1121,1122],{},"your operating system",[28,1124,1125],{},"other programs running",[28,1127,1128],{},"normal scheduling delays",[14,1130,1131,1132,1134],{},"So ",[17,1133,243],{}," means “wait about 1 second,” not “wait with perfect precision.”",[48,1136,1138],{"id":1137},"when-to-use-it","When to use it",[14,1140,1141,1143],{},[17,1142,19],{}," is a good choice for simple beginner programs.",[14,1145,1146],{},"Common uses:",[25,1148,1149,1152,1155,1158],{},[28,1150,1151],{},"simple delays in scripts",[28,1153,1154],{},"basic countdown timers",[28,1156,1157],{},"spacing out repeated actions",[28,1159,1160],{},"learning how program flow works",[14,1162,1163],{},"It is especially helpful when you want to see your program run step by step.",[48,1165,1167],{"id":1166},"when-not-to-use-it","When not to use it",[14,1169,1170,1172],{},[17,1171,19],{}," is not the best tool in every situation.",[14,1174,1175],{},"It is not ideal when:",[25,1177,1178,1181,1184],{},[28,1179,1180],{},"you need precise timing",[28,1182,1183],{},"your program must stay responsive during the delay",[28,1185,1186],{},"you want other work to continue at the same time",[14,1188,1189],{},"To beginners, a sleeping program can look frozen. That is normal. While the program is sleeping, that part of the code is not doing anything else.",[48,1191,1193],{"id":1192},"faq","FAQ",[542,1195,1197],{"id":1196},"does-timesleep-use-seconds-or-milliseconds","Does time.sleep() use seconds or milliseconds?",[14,1199,1200,1201,112],{},"It uses seconds. You can use decimals for part of a second, such as ",[17,1202,153],{},[542,1204,1206],{"id":1205},"can-i-use-timesleep01","Can I use time.sleep(0.1)?",[14,1208,1209],{},"Yes. A float value is valid and pauses for a fraction of a second.",[542,1211,1213],{"id":1212},"why-does-my-program-seem-frozen","Why does my program seem frozen?",[14,1215,1216,1218],{},[17,1217,19],{}," pauses execution, so nothing else in that part of the program runs during the delay.",[542,1220,1222],{"id":1221},"why-do-i-get-an-error-when-i-use-sleep2","Why do I get an error when I use sleep(2)?",[14,1224,1225],{},"You probably forgot to import it correctly.",[14,1227,1228],{},"Use:",[53,1230,1232],{"className":55,"code":1231,"language":57,"meta":58,"style":58},"import time\ntime.sleep(2)\n",[17,1233,1234,1240],{"__ignoreMap":58},[62,1235,1236,1238],{"class":64,"line":65},[62,1237,69],{"class":68},[62,1239,73],{"class":72},[62,1241,1242,1244,1246,1248,1250,1252],{"class":64,"line":76},[62,1243,45],{"class":72},[62,1245,112],{"class":90},[62,1247,116],{"class":115},[62,1249,91],{"class":90},[62,1251,122],{"class":121},[62,1253,104],{"class":90},[14,1255,1256],{},"Or:",[53,1258,1260],{"className":55,"code":1259,"language":57,"meta":58,"style":58},"from time import sleep\nsleep(2)\n",[17,1261,1262,1272],{"__ignoreMap":58},[62,1263,1264,1266,1268,1270],{"class":64,"line":65},[62,1265,1059],{"class":68},[62,1267,1062],{"class":72},[62,1269,69],{"class":68},[62,1271,1067],{"class":72},[62,1273,1274,1276,1278,1280],{"class":64,"line":76},[62,1275,116],{"class":115},[62,1277,91],{"class":90},[62,1279,122],{"class":121},[62,1281,104],{"class":90},[542,1283,1285],{"id":1284},"is-the-delay-always-exact","Is the delay always exact?",[14,1287,1288],{},"No. It is usually close, but the exact timing can vary slightly.",[48,1290,1292],{"id":1291},"see-also","See also",[25,1294,1295,1301,1305,1311,1315],{},[28,1296,1297],{},[196,1298,1300],{"href":1299},"\u002Fstandard-library\u002Fpython-time-module-overview","Python time module overview",[28,1302,1303],{},[196,1304,199],{"href":198},[28,1306,1307],{},[196,1308,1310],{"href":1309},"\u002Fhow-to\u002Fhow-to-exit-a-program-in-python","How to exit a program in Python",[28,1312,1313],{},[196,1314,531],{"href":530},[28,1316,1317],{},[196,1318,1319],{"href":823},"NameError: name is not defined fix",[1321,1322,1323],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":58,"searchDepth":76,"depth":76,"links":1325},[1326,1327,1328,1329,1330,1331,1337,1343,1344,1345,1352],{"id":50,"depth":76,"text":51},{"id":156,"depth":76,"text":157},{"id":203,"depth":76,"text":204},{"id":301,"depth":76,"text":302},{"id":387,"depth":76,"text":388},{"id":534,"depth":76,"text":535,"children":1332},[1333,1334,1335,1336],{"id":544,"depth":83,"text":545},{"id":595,"depth":83,"text":596},{"id":646,"depth":83,"text":647},{"id":700,"depth":83,"text":701},{"id":743,"depth":76,"text":744,"children":1338},[1339,1340,1341,1342],{"id":752,"depth":83,"text":753},{"id":827,"depth":83,"text":828},{"id":981,"depth":83,"text":982},{"id":1108,"depth":83,"text":1109},{"id":1137,"depth":76,"text":1138},{"id":1166,"depth":76,"text":1167},{"id":1192,"depth":76,"text":1193,"children":1346},[1347,1348,1349,1350,1351],{"id":1196,"depth":83,"text":1197},{"id":1205,"depth":83,"text":1206},{"id":1212,"depth":83,"text":1213},{"id":1221,"depth":83,"text":1222},{"id":1284,"depth":83,"text":1285},{"id":1291,"depth":76,"text":1292},"Master time.sleep function explained in our comprehensive Python beginner guide.","md",{},"\u002Fstandard-library\u002Ftime.sleep-function-explained",{"title":5,"description":1353},"standard-library\u002Ftime.sleep-function-explained","yUWK8e6_JRz8fIt2Aor6zfYOSdfwW7kOTtUTeQY-mVQ",1777585471214]