獲取python的版本&獲取兩個日期的天數差值


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, "\n", is_py2, is_py3)
print(retire_msg)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM