number: 1,2,...n
import math
import random
random.random()
random.choice( [1,2,3,4,5,6] )
string:str1='heha da'
'%s is a big fool %s'% ('jiang','that is absolutely')
#序列的method
str1[1]:'e'
slice:str1[1:4]
+,*
#string method
str1.find('a')
str2=str1.replace('ha','sb')
list:list1=[1,'asdf','a',...]
#list method
list1.append( 'x' )#栈底插入
list1.pop(2)#弹出index=2的元素
list1.sort()#对象的方法,只对对象自身产生作用,整体是个函数,没有返回值
list1.reverse()
dict:{host:'192.168.1.102',device_num:5,....}
dict1={'food':'spam','quantity':4}
dict1['quantity']+=1
tuple:(1,'fixed one',...)
set: set( ['x','y','z'] )
X&Y X|Y X-Y
file: file1=open('data.txt','w')
file1.write('Hello\n')
file1.close()
file2=open('data.txt','r')
text=file2.read()
print text
#user def type(class)#coding=utf-8
class worker:
def _init_(self,name,pay):
self.name=name
self.pay=pay
def lastname(self):
return self.name.split[-1]
def givenrise(self):
return self.pay
worker1=worker('jonathan',10000)
print worker1.lastname()+"\n"+worker1.givenrise()