python reserved word
Reserved words are keywords, and we cannot use them as any identifier name. Python's standard library provides a keyword module, which can output all keywords of the current version:
>>> import keyword >>> keyword.kwlist ['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] >>>
python comments
Single-Line Comments
# This is a single line comment
multiline comment
''' Python It is an interpretive language: this means that there is no compilation in the development process. be similar to PHP and Perl Language. Python Is an interactive language: this means that you can Python Prompt >>> Execute the code directly after. Python Is an object-oriented language: That means Python Support object-oriented style or code encapsulated in object programming technology. '''
python indent
The most distinctive feature of python is that it uses indentation to represent code blocks without curly braces {}.
if True: print ("True") else: print ("False")
If the indents are inconsistent, it will cause a running error
if True: print("True") else: print("False") print("False") # File "C:/**/**/***/***.py", line ** # print("False") ^ # IndentationError: unindent does not match any outer indentation level
python multiline statement
If an expression / statement is very long, we can use ` ` to realize multi line statement and line feed display
total = val_1 + \ val_2 + \ val_3 - \ val_4
Multiline statements in [], {}, or () do not require backslashes``
In the dictionary {}
num_dict = { 'num_1': 1, 'num_2': 2, 'num_3': 3 } # print ---- {'num_1': 1, 'num_2': 2, 'num_3': 3}
In the list []
num_list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ] # print ---- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
In tuple ()
num_tuple = ( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) # print ---- (1, 2, 3, 4, 5, 6, 7, 8, 9)
python displays multiple statements on the same line
Use semicolons between statements; division
print(num_dict); print(num_tuple); print(num_list)
python print output and output do not wrap
print('python print output')
The default output of print is newline. If you want to realize no newline, you need to add end = "" at the end of the variable:
print( 'Hello', end=" " ) print( 'python') # Output ----- > > Hello python print( 'Hello', end="*" ) print( 'python') # Output ----- > > Hello * ython
python multiple statements form a code group
Indent the same set of statements to form a code block, which we call a code group.
For compound statements such as if, while, def and class, the first line starts with a keyword and ends with a colon (:), and one or more lines of code after this line form a code group.
We call the first line and the following code group a clause.
if val : pass elif val_2 : pass else : pass
python import and from... Import
In python, use import or from... Import to import the corresponding module.
Import the whole module in the format of import somemodule
Import a function from a module in the format from some module import somefunction
Import multiple functions from a module in the form of: from somemodule import firstfunc, secondfunc, thirdffunc
Import all functions in a module in the format from some module import*
Import sys module
import sys for i in sys.argv: print (i) print ('\n python Path is', sys.path)
Import argv and path members of sys module
# Import specific members from sys import argv,path # Because the path member has been imported, you do not need to add sys path print('path:', path)
Python experience sharing
It's good to learn Python well, whether in employment or sideline, but to learn python, you still need to have a learning plan. Finally, let's share a full set of Python learning materials to help those who want to learn Python!
1, Python learning routes in all directions
All directions of Python is to sort out the common technical points of Python and form a summary of knowledge points in various fields. Its usefulness is that you can find corresponding learning resources according to the above knowledge points to ensure that you learn more comprehensively.
2, Learning software
If a worker wants to do well, he must sharpen his tools first. The commonly used development software for learning Python is here, which saves you a lot of time.
3, Getting started video
When we watch videos, we can't just move our eyes and brains without hands. The more scientific learning method is to use them after understanding. At this time, the hand training project is very suitable.
4, Actual combat cases
Optical theory is useless. We should learn to knock together and practice, so as to apply what we have learned to practice. At this time, we can make some practical cases to learn.
5, Interview materials
We must learn Python in order to find a high paying job. The following interview questions are the latest interview materials from front-line Internet manufacturers such as Ali, Tencent and byte, and Ali has given authoritative answers. After brushing this set of interview materials, I believe everyone can find a satisfactory job.
This complete set of Python learning materials has been uploaded to CSDN. If necessary, friends can scan the official authentication QR code of CSDN below on wechat and get it for free [guaranteed to be 100% free].