Home > Backend Development > Python Tutorial > python syntax concatenation

python syntax concatenation

不言
Release: 2018-05-05 14:44:49
Original
2177 people have browsed it

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()
Copy after login

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

##save_file = open(“save.dat”, “wb ”) pickle.dump(game_data,
save.file)
save_file.close()

Open:

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_file = open(“save.dat”, “rb”) load_game_data = pickle.load(
load_file)
load_file.close()

Open:

File variable = open("File path file name", "rb")

Save:

Variable to put the content = pickle.load(file variable)

Close:

File variable.close()


Ubuntu vim

Value String " " List[] Tuple ( ) Tuple {}

Conditional statement if Loop statement for while

Code vertical alignment table hierarchical relationship
Function def Object t. Class Class Module import Package from
Object-oriented programming
File read and write operations

Related recommendations:

Detailed explanation of Python syntax basics

##Python syntax quick start guide

The above is the detailed content of python syntax concatenation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template