Hello everyone , I'm Ning Yi .
In this class, let's talk about some Python Basic knowledge of .
print() It is the most commonly used Python function , Not one of them. , Can't understand the code, find him , Come to him when you have problems , The inspection procedure also looks for him , A warm man .
It's easy to use .
Basic grammar :
print(" Output content ")
Now let's print out the first sentence ~
(1) Open the terminal
Terminal open mode :
Mac: Start up stage Search for terminal
Windows: Start Search for cmd
(2) Get into Python Interactive environment
Windows The environment is input at the terminal python.
Mac The environment is input at the terminal python3.
appear python Version and prompt >>>, It means that you have successfully entered the interactive environment .
We can at the prompt >>> Type in Python Code .
(3) Enter the code
At the prompt >>> Type in print("Hello World”) Back carriage return , The system will print it out Hello World.
>>> print("Hello World") # Input Hello World # Output
Some friends may have some questions here , Why not use the code editor we installed last class to write code , Instead, write in the terminal .
You can write code in both the terminal and the code editor , We often test some simple functions in the terminal , Edit complex functions in the code editor .
The content of the previous lessons is relatively simple , We write directly in the terminal , Later, it will gradually go to the code editor , So after the course , You can write code in two ways .
A note is actually a paragraph of text , We want to add a textual explanation to the code , I don't want this text explanation to be run as code .
At this time, you can use comments .
function 、 Class must be annotated with a block , Code key parameters and key positions need to add line comments , You also need to avoid unnecessary comments .
Basic grammar :
(1) Single-line comments
If the comment has only one line , Put a pound sign in front of it # Can .
# Output Hello world( I am a comment )print('Hello world') # I'm also a commentator ( This is not recommended )
(2) Multiline comment
If you want multi line comments , Use three English single quotation marks in pairs (''' ''') Or the Pair three English double quotation marks (""" """) Wrap the text .
""" I am a comment with three double quotation marks """''' I am a comment with three single quotation marks '''
Click to follow ,Python Get started and don't get lost ~