# Python3 vs Python2

Python3 은 Python2.x 라인과는 양립할 수 없기 때문에 Python3 만의 특징을 알아야합니다.

## Python3 장점  💎

**VirtualEnv 내장**

* Python2 에서는 프로젝트별 가상환경 셋팅을 위해 VirtualEnv 를 사용하려고 할때, 먼저 pip 을 통하여 패키지를 설치해야만 했습니다.
* 하지만 Python3 에서는 VirtualEnv 가 내장되어 있기 때문에 pyenv 명령어만으로 사용할 수 있습니다.

**Unicode 지원**

* Python2 의 기본 인코딩이 Ascii 이다 보니, 스크립트에서 한글을 사용하게 되면 SyntaxError 가 발생했습니다.
* Python3 에서는 유니코드가 포함된 String 은 모두 유니코드로 저장하기 때문에 스크립트상에서 한글을 사용하기 편리합니다.

**상세한 Error Exception**

* Python3 에서는 예외가 발생했을때 알려주는 에러 메세지가 상세합니다.&#x20;
* 특정 예외를 받아 또 다른 예외를 발생시킬때, 그 과정을 더 상세히 알려줍니다.

## Python2 vs Python3&#x20;

실제로 Python3 코딩을 하면서 Python2 와 문법이 달라서 당황했던 부분들을 정리해보았습니다.

#### **print vs print ("")**

* Python2

```
print "python2"
```

* Python3

```
print ("python3")
```

#### **xrange vs range**

* Python2 가 제공하던 `xrange` 를 사용하면 데이터 크기와 상관없이 Memory 할당량을 동일하게 유지하여 Memory 효율을 높일 수 있었습니다.
* 하지만 Python3 에서는 더이상 `xrange` 를 지원하지 않습니다. 무조건 `range` 만 사용할 수 있습니다.

참고: Python 공식 사이트


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haleyryu.gitbook.io/engineer/python/python3/python2-vs-python3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
