[참조]
버전 | 릴리즈 날짜 | 주요 특징 | 지원 종료 |
---|---|---|---|
Python 0.9.0 | 1991년 2월 | 최초 공개 버전, 클래스와 예외 처리 포함 | - |
Python 1.0 | 1994년 1월 | lambda, map, filter, reduce 함수 추가 | - |
Python 1.5 | 1997년 12월 | 정규표현식 모듈 추가 | - |
Python 2.0 | 2000년 10월 | 리스트 컴프리헨션, 가비지 컬렉션 도입 | - |
Python 2.7 | 2010년 7월 | Python 2의 마지막 메이저 릴리즈 | 2020년 1월 |
Python 3.0 | 2008년 12월 | 하위 호환성 중단, 유니코드 기본 지원 | 2009년 6월 |
Python 3.6 | 2016년 12월 | f-string, 타입 힌팅 개선 | 2021년 12월 |
Python 3.9 | 2020년 10월 | 딕셔너리 병합 연산자, 타입 힌팅 개선 | 2025년 10월 |
Python 3.12 | 2023년 10월 | 개선된 에러 메시지, 성능 최적화 | 2028년 10월 |
print "Hello World"
형태로 사용5/2 = 2
(정수 결과)u"문자열"
과 "문자열"
분리
# Python 2 예시
print "Hello, World!" # print 문
# 문자열 처리
unicode_str = u"안녕하세요"
byte_str = "Hello"
# 정수 나눗셈
result = 5 / 2 # 결과: 2
# 반복자
for i in xrange(10):
print i
print("Hello World")
형태로 통일5/2 = 2.5
(실수 결과), 정수 나눗셈은 //
사용except Exception as e:
구문 표준화
# Python 3 예시
print("Hello, World!") # print 함수
# 문자열 처리 (모든 문자열이 유니코드)
message = "안녕하세요"
greeting = "Hello"
# 나눗셈 연산
float_result = 5 / 2 # 결과: 2.5
int_result = 5 // 2 # 결과: 2
# 반복자
for i in range(10):
print(i)
# 예외 처리
try:
result = 10 / 0
except ZeroDivisionError as e:
print(f"오류 발생: {e}")
구분 | Python 2 | Python 3 | 설명 |
---|---|---|---|
print "text" |
print("text") |
문에서 함수로 변경 | |
나눗셈 | 5/2 = 2 |
5/2 = 2.5 |
기본 나눗셈이 실수 나눗셈으로 변경 |
문자열 | str 과 unicode 분리 |
모든 문자열이 유니코드 | 유니코드 처리 단순화 |
range | range() , xrange() |
range() 만 존재 |
xrange 기능이 range로 통합 |
반복자 | dict.keys() 는 리스트 |
dict.keys() 는 뷰 객체 |
메모리 효율성 개선 |
예외 처리 | except Exception, e: |
except Exception as e: |
구문 일관성 개선 |
입력 함수 | raw_input() , input() |
input() 만 존재 |
raw_input이 input으로 변경 |
# -*- coding: utf-8 -*-
print "안녕하세요"
result = 5 / 2
print "결과:", result
name = raw_input("이름을 입력하세요: ")
print "안녕하세요, %s님!" % name
# 딕셔너리 키 순회
data = {"a": 1, "b": 2}
for key in data.keys():
print key, data[key]
print("안녕하세요")
result = 5 / 2
print("결과:", result)
name = input("이름을 입력하세요: ")
print(f"안녕하세요, {name}님!")
# 딕셔너리 키 순회
data = {"a": 1, "b": 2}
for key in data.keys():
print(key, data[key])
# 명령행에서 사용
$ 2to3 -w example.py
# Python 2 코드
print "Hello"
result = 5 / 2
# 변환 후 Python 3 코드
print("Hello")
result = 5 / 2
# 바다코끼리 연산자 (Walrus operator)
if (n := len(data)) > 5:
print(f"리스트가 너무 깁니다: {n}개 항목")
# Positional-only 매개변수
def greet(name, /):
return f"안녕하세요, {name}님!"
# 딕셔너리 병합 연산자
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
merged = dict1 | dict2
# 문자열 메서드 개선
text = " hello world "
clean_text = text.removeprefix(" ").removesuffix(" ")
# 구조적 패턴 매칭 (match-case)
def process_data(data):
match data:
case int() if data > 0:
return f"양의 정수: {data}"
case str() if len(data) > 0:
return f"문자열: {data}"
case []:
return "빈 리스트"
case _:
return "알 수 없는 형태"
import this
# The Zen of Python 중 일부
# Beautiful is better than ugly.
# Explicit is better than implicit.
# Simple is better than complex.
# Complex is better than complicated.
# Readability counts.
결론: Python은 Python 2에서 Python 3로의 전환을 통해 언어적 완성도를 크게 높였으며, 현재는 전 세계에서 가장 인기 있는 프로그래밍 언어 중 하나로 자리잡았습니다. 지속적인 발전과 강력한 커뮤니티를 바탕으로 앞으로도 다양한 분야에서 핵심적인 역할을 할 것으로 전망됩니다.