python 数据
2015-05-31 10:45
507 查看
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()
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()
相关文章推荐
- python str.translate()函数用法
- Python 3 -Functions
- python Asyncore.dispatcher 理解
- Python开发安装的一些常用模块
- python第三方库系列之十六--建立最简单的web服务器
- Python装饰器学习笔记
- 从python协程理解tornado异步
- python 多线程服务器示例
- Python yield 用法
- Python通过文件头来判断文件的真实类型
- 在pythonanywhere上搭建django程序(Virtualenv+python2.7+django1.7+)
- python学习笔记之――函数模块
- 【python】数据库操作
- Python删除列表重复数据以及效率问题
- 从底层理解Python的执行
- win32系统 python3.4 安装matplotlib
- Python进行中文注释
- python 轻量级邮件发送库
- 测试python awk sed 读取文件指定位置时的性能
- Python学习之路二