3-1-5-27. Experimenting with an Interpreter

You can type here to interact with Python directly.

You just type your code,

press enter and the output will appear on the following line.

This is a good place to experiment and try bits of Python code at a time.

Notice here, I didn’t have to print the type to see the output.

In the interpreter, the value of the last line

in a prompt will be outputted automatically.

If you had multiple lines where you’d want output values,

you’d still have to print.

If you start to define a function,

you will see a change in the prompt to signify that this is a continuation line.

You’ll have to include your own indentation as you defined the function.

A drawback of the interpreter is that it’s tricky to edit code.

If you made a mistake when typing

this function or forgot to indent the body of the function,

you can’t use a mouse to click your cursor where you want it.

You have to navigate with the arrow keys to move

the cursor forwards and backwards to the line itself for editing.

It would be helpful for you to learn useful shortcuts

for actions like moving to the beginning or end of the line.

Notice, I can reference any objects I defined earlier in the interpreter.

One useful trick is using the up and down arrow

to cycle through your recent commands at the interactive prompt.

This can be useful to rerun or adapt code you’ve already tried.

To quit the python interactive interpreter,

use the command exit with parentheses or hit control

D on mac or linux or control Z and enter for Windows.

There’s actually a really good alternative to the default python interpreter.

IPython which comes as many additional features like

tab completion which completes words for you

or shows what options are available if there are multiple.

This can be useful if you want to see what methods are available for an object.

Another useful check is this question mark to get details about a particular object.

I can quickly see what this function does without looking up the documentation.

You can also execute system shell commands using

an exclamation point and some common ones don’t even require it.

You can learn more about IPython in the notes below.

Using an interpreter can be really helpful for experimenting and testing python code.

Those not necessarily just for experimentation.

I also used an interpreter when I want to quickly

investigate or modify files using Python.

터미널을 열고 python을 입력하면,

당신은 이것과 같은 것을보아야합니다.

이것은 파이썬 인터랙티브 인터프리터입니다.

여기에 입력하여 Python과 직접 상호 작용할 수 있습니다.

코드를 입력하면 됩니다.

Enter 키를 누르면 다음 줄에 출력이 나타납니다.

이것은 한 번에 약간의 Python 코드를 실험하고 시도하기에 좋은 장소입니다.

여기에서 출력을 보기 위해 유형을 인쇄할 필요가 없습니다.

인터프리터에서 마지막 줄의 값

프롬프트에서 자동으로 출력됩니다.

출력 값을 원하는 라인이 여러 개 있는 경우

여전히 인쇄해야 합니다.

함수를 정의하기 시작하면,

이것이 연속 라인임을 나타내는 프롬프트에 변경 사항이 표시됩니다.

함수를 정의할 때 고유한 들여쓰기를 포함해야 합니다.

인터프리터의 단점은 코드를 편집하기가 까다롭다는 것입니다.

입력할 때 실수를 했다면

이 함수 또는 함수 본문 들여쓰기를 잊어버린 경우

마우스를 사용하여 원하는 위치에 커서를 클릭할 수 없습니다.

이동하려면 화살표 키를 사용하여 탐색해야 합니다.

커서는 편집을 위해 줄 자체로 앞뒤로 움직입니다.

유용한 단축키를 배우는 데 도움이 될 것입니다.

줄의 시작 또는 끝으로 이동하는 것과 같은 작업에 사용됩니다.

앞서 인터프리터에서 정의한 모든 개체를 참조할 수 있습니다.

유용한 트릭 중 하나는 위쪽 및 아래쪽 화살표를 사용하는 것입니다.

대화형 프롬프트에서 최근 명령을 순환합니다.

이것은 이미 시도한 코드를 다시 실행하거나 조정하는 데 유용할 수 있습니다.

파이썬 대화형 인터프리터를 종료하려면,

괄호와 함께 명령 종료를 사용하거나 컨트롤을 누르십시오.

Mac 또는 Linux에서는 D를, Windows에서는 Z를 제어하고 Enter 키를 누릅니다.

실제로 기본 파이썬 인터프리터에 대한 정말 좋은 대안이 있습니다.

다음과 같은 많은 추가 기능이 제공되는 IPython

당신을 위해 단어를 완성하는 탭 완성

또는 여러 옵션이 있는 경우 사용할 수 있는 옵션을 보여줍니다.

이는 개체에 사용할 수 있는 메서드를 확인하려는 경우에 유용할 수 있습니다.

또 다른 유용한 검사는 특정 개체에 대한 세부 정보를 얻기 위한 이 물음표입니다.

문서를 검색하지 않고도 이 기능이 무엇을 하는지 빠르게 알 수 있습니다.

다음을 사용하여 시스템 셸 명령을 실행할 수도 있습니다.

느낌표와 일부 일반적인 것들은 필요하지 않습니다.

아래 참고 사항에서 IPython에 대해 자세히 알아볼 수 있습니다.

인터프리터를 사용하면 파이썬 코드를 실험하고 테스트하는 데 정말 도움이 될 수 있습니다.

반드시 실험을 위한 것은 아닙니다.

저도 빨리 하고 싶을 때 통역을 이용했어요

Python을 사용하여 파일을 조사하거나 수정합니다.

Experimenting With An Interpreter

Start your Python interactive interpreter by entering the command python in your terminal. You can type here to interact with Python directly. This is an awesome place to experiment and try bits of Python code at a time. Just enter Python code, and the output will appear on the next line.

>>> type(5.23)
<class 'float'>

In the interpreter, the value of the last line in a prompt will be outputted automatically. If you had multiple lines where you’d want to output values, you’d still have to use print.

If you start to define a function you will see a change in the prompt, to signify that this is a continuation line. You’ll have to include your own indentation as you define the function.

>>> def cylinder_volume(height, radius):
...         pi = 3.14159
...         return height * pi * radius ** 2

A drawback of the interpreter is that it’s tricky to edit code. If you made a mistake when typing this function, or forgot to indent the body of the function, you can’t use the mouse to click your cursor where you want it. You have to navigate with arrow keys to move the cursor forwards and backwards through the line itself for editing. It would be helpful for you to learn useful shortcuts for actions like moving to the beginning or end of the line.

Notice I can reference any objects I defined earlier in the interpreter!

>>> cylinder_volume(10, 3)
282.7431

One useful trick is using the up and down arrow to cycle through your recent commands at the interactive prompt. This can be useful to re-run or adapt code you’ve already tried.

To quit the Python interactive interpreter, use the command exit() or hit ctrl-D on mac or linux, and ctrl-Z then Enter for windows.

IPython

There is actually an awesome alternative to the default Python interactive interpreter, IPython, which comes with many additional features.

  • tab completion
  • ? for details about an object
  • ! to execute system shell commands
  • syntax highlighting!

and a lot more you can find here!

https://ipython.org/ipython-doc/3/interactive/tutorial.html

%d 블로거가 이것을 좋아합니다: