How do I check what version of Python is running my script?

前端 未结 22 2311
醉话见心
醉话见心 2020-11-22 04:11

How can I check what version of the Python Interpreter is interpreting my script?

22条回答
  •  無奈伤痛
    2020-11-22 04:39

    If you want to detect pre-Python 3 and don't want to import anything...

    ...you can (ab)use list comprehension scoping changes and do it in a single expression:

    is_python_3_or_above = (lambda x: [x for x in [False]] and None or x)(True)
    

提交回复
热议问题