import sys from datetime import datetime # Syntax sugar. _ver = sys.version_info # 获取python版本 #: Python 2.x? is_py2 = (_ver[0] == 2) # is_py2 类型为布尔型,返回 False 或 True #: Python 3.x? is_py3 = (_ver[0] == 3) retire_day = datetime(2020, 1, 1) today = datetime.now() left_days = (retire_day - today).days # 获取两个日期的天数差值 if left_days > 0: retire_msg = "Python 2 will retire in {} days, why not move to Python 3?".format(left_days) else: retire_msg = "Python 2 has been retired, you should move to Python 3." print(_ver, " ", is_py2, is_py3) print(retire_msg)