Programming/python

Python에서 __future__ 모듈의 기능

방황하는 데이터불도저 2022. 11. 14. 17:05

python2버전에서 3버전으로 업데이트되면서 몇몇의 문법이나 기능이 달라졌다.

 

구버전 Python2에서도 상위버전 Python3의 기능을 사용할 수 있게 해주는 모듈

https://docs.python.org/3/library/__future__.html

 

__future__ — Future statement definitions — Python 3.11.0 documentation

__future__ — Future statement definitions Source code: Lib/__future__.py __future__ is a real module, and serves three purposes: To avoid confusing existing tools that analyze import statements and expect to find the modules they’re importing. To ensur

docs.python.org

 

대표적인 예시

from __future__ import print_function

# Python2
# print "Hello World"

# Python3
print("Hello World")