from time import sleep import time import os class Clock(object): """数字时钟""" def __init__(self, hour=0, minute=0, second=0): """初始化方法 :param hour: 时 :param minute: 分 :param second: 秒 """ self._hour = hour self._minute = minute self._second = second def run(self): """走字""" self._second += 1 if self._second == 60: self._second = 0 self._minute += 1 if self._minute == 60: self._minute = 0 self._hour += 1 if self._hour == 24: self._hour = 0 def show(self): """显示时间""" return '%02d:%02d:%02d' % \ (self._hour, self._minute, self._second) def main(): localtime = time.asctime( time.localtime(time.time()) ) hour = int(localtime[11:13]) min = int(localtime[14:16]) sec = int(localtime[17:19]) clock = Clock(hour, min, sec) while True: print(clock.show()) sleep(1) clock.run() os.system('cls') if __name__ == '__main__': main()
Get the system time,
import time localtime = time.asctime( time.localtime(time.time()) )
int type cast in python
hour = int(localtime[11:13])
String interception in python
= STR '0123456789 ' print STR [0:. 3] # , taken first to third character print STR [:] # taken all the character string print STR [. 6:] # taken to the end of the seventh character print STR [: -. 3] # , taken from the beginning until the antepenultimate characters Print STR [2] # taken third character Print STR [-1] # taken penultimate character Print STR [:: -. 1] # creating a reverse order of the strings and the original string print STR [-3: -1] # taken characters and the bottom third of the penultimate one previous print STR [-3:] # taken countdown to the end of the third print str [: - 5: -3] # reverse the interception, did not thoroughly understand the specific what do you mean?
python empty terminal
import the os.system ( ' cis ' )