파이썬 프로그램은 2가지 방식으로 가동되는데, 첫 째 방식은 파이썬 shell에 명령을 직접 타이핑하는 것이고 두 번째 방식은 파일에 저장된 프로그램을 가동하는 것입니다.
대부분은 파이일 저장된 프로그램을 가동합니다.
You can run python programs in two ways, first by typing commands directly in python shell or run program stored in a file. But most of the time you want to run programs stored in a file.
notepad (또는 다른 text editor)를 사용하여, 문서 디렉토리(C:\Users\YourUserName\Documents)에 hello.py란 이름의 파일을 만드시는데, 파이썬 파일은 '.py' 확장을 갖고 있고, 다음 코드를 파일에 작성합니다.
Lets create a file named hello.py in your documents directory i.eC:\Users\YourUserName\Documents using notepad (or any other text editor of your choice) , remember python files have ‘.py’ extension, then write the following code in the file.
파이썬에서는 문자를 콘솔에 표시할 때 print라는 함수를 사용합니다.
print 함수는 1개 이상의 아규먼트를 수용합니다.
2개 이상의 아규먼트를 전달하려면 print 함수는 공백(space)으로 각각의 아규먼트를 분리합니다.
In python we use print function to display string to the console. It can accept more than one arguments. When two or more arguments are passed, print function displays each argument separated by space.
Expected output
Now open terminal and change current working directory toC:\Users\YourUserName\Documents using cd command.
To run the program type the following command.
If everything goes well, you will get the following output.
Getting Help
Sooner or later while using python you will come across a situation when you want to know more about some method or functions. To help you Python has help() function, here is how to use it.
Syntax:
To find information about class: help(class_name)
To find more about method belong to class: help(class_name.method_name)
Suppose you want to know more about int class, go to Python shell and type the following command.
as you can see help() function spits out entire int class with all the methods, it also contains description where needed.
Now suppose you want to know arguments required for index() method of str class, to find out you need to type the following command in the python shell.
In the next post we will learn about data types and variables in python.
'Python 배우기' 카테고리의 다른 글
변수_정의 variable_definition.py (0) | 2016.03.06 |
---|---|
Python Object and Classes 파이썬 객체와 클래스 (0) | 2016.03.05 |
Applications for Python 파이썬 적용 (0) | 2016.03.05 |
PyQt5 Beginner tutorial (0) | 2016.03.04 |
First Steps (0) | 2016.01.05 |
댓글