Next lesson: Start Python(Ii)
Installation and Preparation
mac osPython, my own pythonPython 2.7.16windowsStudents, pleaseDownload the python- There is an editor that can write code or a TXT text editor (e.g.
notepad++)
File execution mode
pythonThe file suffix is.pyFile naming, following all the way files are created- use
pythonKeyword executionCD Current python file directory python test.pyCopy the code - As self-executing
pythonfile- The.py header file identifies the current executable file
#! /usr/bin/python Copy the code - Changes the current file to an executable file
Chmod +x File nameCopy the code
- The.py header file identifies the current executable file
Basic debugging
printPrints the current running value
Add comment information
- The new learning language, cannot leave the annotation, the way to add annotation
- Single-line comments
#Before or at the end of the line#character
# This is a line comment print('I was output... ') # This is the code ready for output Copy the code - Multiline comment
' ' 'or"" "Three single quotes in pairs, or three double quotes
""" I'm the first line comment I'm the second line comment I'm the third line comment "" Copy the code
Sets the character encoding of the file
- If you are in the print above, try to print Chinese and find an error
- That’s right
- To print non-ASCII characters, declare the type of the current file at the head of the file
# coding=utf-8
Copy the code
Hello, python
- Okay, now it’s time to say hello
# coding=utf-8
hello = 'hello'
print '%r %r' % (hello, 'Python')
Copy the code