Common functions for math in python
math.float(), converted to the largest integer less than or equal to this number "is used less", because int can be used
引入的三种方法:
import math
math.sqrt()
import matplotlib as plt
plt.plot()
from math import sin,pi
sin()
cos()
list in python
Lists in Python can store any type of data, and the __ data types in the same list can also be different __; lists are sequence structures, which can perform basic operations on sequence structures: indexing, slicing, adding, multiplying, and checking members. 1.mkdir l = [1024,0.5,'python'] 2.cd l = [1024,0.5,'python'] print('l[0] --> ',l[0]) print('l[ 1:] --> ',l[1:]) The function in the list 1.append() "Add a new element to the list" l = [1024, 0.5, 'Python'] # Modify the second element in the list l[1] = 5 # add a new element to the list l.append('Hello') print('l[1] -->', l[1]) print('l -->', l) result : l[1] --> 5 l --> [1024, 5, 'Python', 'Hello'] 2.del() "delete the element in the list" l = [1024,0.5,'python'] #delete The second element del l[1] print(' 3. Common methods: 1.count() counts the number of occurrences of an element in the list l = ['a','b','v','c','b'] print('l.count(b ) --> ',l.count('b')) #Output result l.count(b) --> 2 2.index() Find the position where an element first appears in the list (ie index) l = ['a','b','v','c','b'] print("l.index('b') --> ",l.index('b')) #Output l . index('b') --> 1 "Just look for the first one" 3.remove() l = ['a','b','v','c','b'] l.remove( 'b') print('l --> ',l) #Output l --> ['a', 'v', 'c', 'b'] "Only the first delete" 4.sort() l = ['a','b','v','c','b'] l.sort() print('l --> ',l) #output l --> [' a', 'b', 'b', 'c', 'v'] 5.copy() copy list l = ['a','b','v','c','b'] lc = l.copy() print('lc --> ',lc) #输出 lc --> ['a', 'b', 'v', 'c', 'b']
Tuples in Python
A tuple is similar to a list, but a tuple is immutable and can be simply regarded as an immutable list. Tuples are often used to store unmodifiable content. 1.mkdir t = (1024, 0.5, 'Python') print('t[0] -->', t[0]) print('t[1:] -->', t[1:]) #Output result: t[0] --> 1024 t[1:] --> (0.5, 'Python') 2. Modify "The elements in the tuple cannot be modified, we have to operate by reassignment" t = (1024, 0.5, 'Python') t = (1024, 0.5, 'Python', 'Hello') print('t -->', t) #Output result: t --> (1024, 0.5, 'Python' ', 'Hello') 3. Delete "elements in a tuple cannot be deleted, we can only delete the entire tuple" t = (1024, 0.5, 'Python') del t print('t --> ',t ) #Output result NameError: name 't' is not defined Common method len() 1. print('lens --> ',lens) lens --> 3 2.max() and min() t = ('d', 'b', 'a', 'f', 'd') print('max(t) -->', max (t)) print('min(t) -->', min(t)) output the result max(t) --> f min(t) --> a 3.tuple() "Convert the list to the element Group" t = ['d', 'b', 'a', 'f', 'd'] l = tuple(t) print('l --> ',l) #output result l --> ( 'd', 'b', 'a', 'f', 'd')
Python draw a square
import turtle as t
t.fd(100)
t.left(90)
t.fd(100)
t.left(90)
t.fd(100)
t.left(90)
t.fd(100)
Reference article:
Python Basics (1): Essential Knowledge for Getting Started - Programmer Sought