PythonIsCool - 1장
1장 - 인쇄, 입력 및 변수
목차
Incorrect Code
Syntax Highlighting
The Print Function
The Input Function
Variables
틀린 코드
To start writing your first line of the code, click the first line of code. Now write whatever you want to write on the line and press run. Luckily for you, if you write a code which doesn't make sense, you will see an error like SyntaxError : invalid syntax
in red in the console. There are other types of errors like the UnboundLocalError
, but the most common error right now will the SyntaxError
.
구문 강조
Syntax Highlighting is a feature of text editors that make it easier to read the code. So different code parts will have different colours.
인쇄 기능
The most basic function in Python is print()
. It is a simple function that just writes whatever is in the brackets in the console. For instance, the way to say Hello World!
in Python is print("Hello World!")
. If you write that in code, the output would be Hello World!
. Have a go at saying Hello World!
to Python in your code. Try running your code now by pressing the run button. The output should look like the picture below.
그렇다면 잘한 것입니다! 적절한 Python 코드의 첫 번째 줄을 작성했습니다! 그렇지 않은 경우 코드를 print("Hello World!")
와 비교하고 무엇이 잘못되었는지 파악하십시오.
입력 기능
Input is another common function in Python. It is used to ask the person testing out your code a question. For example, if you want to ask, How are you?
, you would write, 'input("How are you?")'. The picture in the next page shows how the console would look like after you ran the code.
위의 그림에서 코드는 여전히 입력에 대한 사용자의 응답을 기다리고 있으므로 실행이 완료되지 않았습니다.
입력 코드에 응답하면 코드 줄이 공식적으로 완료됩니다.
변수
Variables are words that have values assigned to them. The values could be numbers, lists, strings, etc. An example of setting a variable is in the code below:
hello = "Hello World!"
In the code's case, the variable name is hello
, and the value is Hello World!
. Now if you want to show Hello World!
in the console, you can just set a variable called hello
with the value of Hello World!
like above, and then print(hello)
, bearing in mind that because hello
is a variable, you don't put speech marks around it.
Now if you run the code, the result will be the same as the time you wrote the code print("Hello World!")
.
Another example of a variable is the code below:
ask = input("How old are you?")
If you type up that code, the result will be the same as your first input statement.
As I said, variables can also be numbers, so if you want to assign the variable 'one' the value of the number 1, you will have to do the code below.
one = 1
After you copy the code above, if you have copied it correctly, you shouldn't see any errors, and the console should have nothing on it. That is because you haven't called any functions which use the console to display anything.
Thanks for reading and I hope you learnt something from this!
Reference
이 문제에 관하여(PythonIsCool - 1장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/vulcanwm/pythoniscool-chapter-1-4nca
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
SyntaxError : invalid syntax
in red in the console. There are other types of errors like the UnboundLocalError
, but the most common error right now will the SyntaxError
.print()
. It is a simple function that just writes whatever is in the brackets in the console. For instance, the way to say Hello World!
in Python is print("Hello World!")
. If you write that in code, the output would be Hello World!
. Have a go at saying Hello World!
to Python in your code. Try running your code now by pressing the run button. The output should look like the picture below.How are you?
, you would write, 'input("How are you?")'. The picture in the next page shows how the console would look like after you ran the code. hello = "Hello World!"
hello
, and the value is Hello World!
. Now if you want to show Hello World!
in the console, you can just set a variable called hello
with the value of Hello World!
like above, and then print(hello)
, bearing in mind that because hello
is a variable, you don't put speech marks around it.Now if you run the code, the result will be the same as the time you wrote the code
print("Hello World!")
. ask = input("How old are you?")
one = 1
Reference
이 문제에 관하여(PythonIsCool - 1장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/vulcanwm/pythoniscool-chapter-1-4nca텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)