Python 버전 2와 3 차이

Jmnote (토론 | 기여)님의 2014년 8월 21일 (목) 09:57 판 (→‎개요)

1 개요

Python 2와 3의 차이
파이썬 버전 2와 3의 차이
  • 모든 변수가 class로 다루어진다.
  • 이외에 여러가지 내부적 변화가 있지만, 다음 4가지 정도를 알아두면 된다.

2 print문 괄호 필수 ★★

Python 2
print( 'hello' )
# hello
print 'hello'
# hello
Python 3
print( 'hello' )
# hello
print 'hello'
# Error! invalid syntax

3 String과 Unicode 통일 ★

Python 2
print( type('hello') )
print( type(u'hello') )
# <type 'str'>
# <type 'unicode'>
Python 3
print( type('hello') )
print( type(u'hello') )
# <class 'str'>
# <class 'str'>

4 나누기 결과가 float

Python 2
print( 1/2 )
print( type(1/2) )
# 0
# <type 'int'>
Python 3
print( 1/2 )
print( type(1/2) )
# 0.5
# <class 'float'>

5 long → int로 통일

Python 2
print( 2**30 )
print( type(2**30) )
print( 2**100 )
print( type(2**100) )
# 1073741824
# <type 'int'>
# 1267650600228229401496703205376
# <type 'long'>
Python 3
print( 2**30 )
print( type(2**30) )
print( 2**100 )
print( type(2**100) )
# 1073741824
# <class 'int'>
# 1267650600228229401496703205376
# <class 'int'>

6 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}