Data Structure
List
1 2 3 4
| list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5, 6, 7 ] print ("list1[0]: ", list1[0]) print ("list2[1:5]: ", list2[1:5])
|
Tuple
similar to List, but the element in tuple can’t be changed
1 2 3 4
| tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5, 6, 7 ) print ("tup1[0]: ", tup1[0]) print ("tup2[1:5]: ", tup2[1:5])
|
Dictionary
{ key : value }
1 2 3
| dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} print ("dict['Name']: ", dict['Name']) print ("dict['Age']: ", dict['Age'])
|
Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
class Parent: parentAttr = 100 def __init__(self): print "调⽤⽗类构造函数" def parentMethod(self): print '调⽤⽗类⽅法' def setAttr(self, attr): Parent.parentAttr = attr def getAttr(self): print ("⽗类属性 :", Parent.parentAttr) class Child(Parent): def __init__(self): print ("调⽤⼦类构造⽅法") def childMethod(self): print ('调⽤⼦类⽅法') def func(obj): obj.run()
c = Child() c.childMethod() c.parentMethod() c.setAttr(200) c.getAttr()
|
Pymysql
A Python Library used to connect the database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import pymysql conn = pymysql.connect( host=“你的数据库地址”, user=“⽤户名”,password=“密码”, database=“数据库名”, charset=“utf8”) cursor = conn.cursor() sql = """ CREATE TABLE USER1 ( id INT auto_increment PRIMARY KEY , name CHAR(10) NOT NULL UNIQUE, age TINYINT NOT NULL )ENGINE=innodb DEFAULT CHARSET=utf8; #注意:charset='utf8' 不能写成utf-8 """
cursor.execute(sql)
cursor.close()
conn.close()
|