The content of this article is python syntax concatenation. Now I share it with everyone. Friends in need can refer to the content of the article
for i in range(begin, end)
balabala
for i in liebiaoming:
balabala
while tiaojian:
balabala
break
turtle module
#导入turtle moduleimport turtle #use the Pen in the module of turtle 实例化一个t对象t = turtle.Pen()#向前n个像素点t.forward(n)#向后n个像素点t.backward(n)#←m°t.left(m) t.right(m) t.reset()
function module package
function:
def hhhh (parameter list):
ksjfdlk
Function return value: return
Built-in function: python’s own function
Module: a collection of functions, import first, then use
module.function( )
Package: Contains multiple modules
from PLI import IMagine
Class Object Object-oriented
Class: Function collection, which can instantiate the mold of the object
Instantiation: Object = class() t = turtle.Pen()
Object: entity instantiated by the class,
Object-oriented: optimization class, instance object, call function execution Operation
Definition of class: class class name (parent class name): <br>
pass
The first parameter is self
def __init__ (self, spots): <br>
Pass
#Assign 10 to spots kitty = Cats(10)
The object calls the functions and variables in the class
a.b
When the function is defined in the class, Call functions and variables of itself or the parent class, self.function self.vari.
File operation
File writing—–import pickle
Open:##save_file = open(“save.dat”, “wb ”) pickle.dump(game_data,
save.file)
save_file.close()
File variable = open("File path file name", "wb")Save:
pickle.dump (variable to be written, file variable)Close:
File variable.close()File reading—–import pickle
Open:open_file = open(“save.dat”, “rb”) load_game_data = pickle.load(
load_file)
load_file.close()
File variable = open("File path file name", "rb")Save:
Variable to put the content = pickle.load(file variable)Close:
File variable.close()
Value String " " List[] Tuple ( ) Tuple {}
Code vertical alignment table hierarchical relationship
Function def Object t. Class Class Module import Package from
Object-oriented programming
File read and write operations
Detailed explanation of Python syntax basics
##Python syntax quick start guideThe above is the detailed content of python syntax concatenation. For more information, please follow other related articles on the PHP Chinese website!