티스토리 뷰
-. 함수형태로 변한 print문
python 2 print “python” |
python 3 print(“python”) |
입력인자를 지정해줄수 있음
sep=” “(구분자)
end=”\n”(끝라인)
file=sys.stdout(출력)
-. long형이 없어지고 ing형으로 통일됨
python 2 >>> type(2**63) <type ‘long’> |
python 3 >>> type(2**63) <class ‘int’> |
2에서는 sys.maxint이하의 값은 int로 처리되고 그 이상의 값은 long으로 처리되었는데 3에서부터는 모두 int로 처리됨
-. [ int / int] 의 결과는 float으로 처리됨
python 2 >>> 1/2 0 >>> 3/2 1 |
python 3 >>> 1/2 0.5 >>> 3/2 1.5 |
2에서는 int / int의 결과는 int로만 나왔는데 3부턴 int / int도 float로 반환됨
-. String, Unicode 체계가 바뀌었습니다.
python 2 >>> type("가") <type 'str'> >>> type("가".decode("utf8")) <type 'unicode'> >>> type(u"가") <type 'unicode'> |
python 3 >>> type(u"가") SyntaxError: invalid syntax >>> type("가") <class 'str'> >>> type("가".encode("cp949")) <class 'bytes'> |
Python 2에서는 일반스트링이 인코딩이 있는 문자열이었고 유니코드가 따로 있었는데 Python 3에서는 유니코드를 따로지정하지 않고 일반 스트링이 기존의 유니코드와 동일하며, 인코딩이 있는 문자열은 bytes로 표현됨.
[C:\Python32\Tools\Scripts\2to3.py]을 이용하면 2에서 3으로 간단한 변환이 가능함, 하지만 만능은 아님
'Python' 카테고리의 다른 글
Python, 한줄에 여러구문이 올때 [;],여러줄에 한구문 사용할때[\] (0) | 2016.04.21 |
---|---|
Python, 2.x와 3의 차이 (0) | 2016.04.21 |
Python,module sys (0) | 2016.04.21 |
Python,module os [운영체제] (0) | 2016.04.21 |
Python, Class (0) | 2016.04.21 |
- Total
- Today
- Yesterday
- 폼
- activebackground
- vba
- highlightbackground
- 리눅스
- JPA
- checkbutton
- Private
- Excel
- 상수
- disabledforeground
- tkinter command & bind [명령어묶기와 사건묶기] Python
- highlightthickness
- onetomany
- apache
- Composite Key
- activeforeground
- tkinter
- FetchType
- Python
- Java
- ManyToOne
- Linux
- borderwidth
- command
- fetch join
- indicatoron
- Module
- IdClass
- 파이썬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |