四行代码就可以。
import time
loc_s = time.localtime()
s_tuple = ('年', '月', '日 ', ':', ':', '')
for x, y in zip(loc_s, s_tuple): print(str(x)+y, end='')
也可以让显示好看点
代码
#! /sur/bin/nve python
# coding: utf-8
import time
'''显示当前时间'''
#打印分割线
print('n'+'﹊'*21)
#获取当前时间元组
loc_s = time.localtime()
#格式打印字符元组
s_tuple = ('年', '月', '日 ', ':', ':', '')
#打印显示前导空格的字符串
print(''.rjust(10), end='')
for x, y in zip(loc_s, s_tuple):
print(str(x)+y, end='')
print('n'+'﹊'*21)
显示效果
- Python 完全自学手册
- 海象运算符
- Python中的 `!=`与`is not`不同
- 学习编程的正确方法



