#
其他特性:
filter函数:
res = filter(lambda x: x%2 == 0, list)
print(*res)#输出filter
map函数:
res = map(lambda x: "read %s" %x, list)
print(*res)#遍历list每个元素
range迭代器:
range生成一个没有任何方法的对象,它只有内置方法
range(0, 10)#[0~9]
for x in range(1, 10, 2)#[1~9] step:2
range(0, 10)#数组访问range[0]=0
字典的特色字符串替换:
dic = {'a':1,'b':2,'c':3}
dic['add'] = 10
dic['app'] = 'ext'
print("%(a)d, %(app)s" % dic)#1,ext
import string
str = string.Template("$a is no $app")
print(t.substitute(dic))
从命令行中得到选项getopt:
import sys
import getopt
opts, args = getopt.getopt()# getopt.gnu_getopt()
进程:
import os
pid = os.fork#子进程返回值为0,只工作在UNIX和类UNIX系统上
os.execl('/bin/cat')#新程序代替正在运行的程序的指令
os.wait()#通知Python让父进程等待子进程返回
os.spawn()#函数族,合并了fork(),exec(),可以在Windows上完成类似的工作
os.system(command)#等待结束
filter函数:
res = filter(lambda x: x%2 == 0, list)
print(*res)#输出filter
map函数:
res = map(lambda x: "read %s" %x, list)
print(*res)#遍历list每个元素
range迭代器:
range生成一个没有任何方法的对象,它只有内置方法
range(0, 10)#[0~9]
for x in range(1, 10, 2)#[1~9] step:2
range(0, 10)#数组访问range[0]=0
字典的特色字符串替换:
dic = {'a':1,'b':2,'c':3}
dic['add'] = 10
dic['app'] = 'ext'
print("%(a)d, %(app)s" % dic)#1,ext
import string
str = string.Template("$a is no $app")
print(t.substitute(dic))
从命令行中得到选项getopt:
import sys
import getopt
opts, args = getopt.getopt()# getopt.gnu_getopt()
进程:
import os
pid = os.fork#子进程返回值为0,只工作在UNIX和类UNIX系统上
os.execl('/bin/cat')#新程序代替正在运行的程序的指令
os.wait()#通知Python让父进程等待子进程返回
os.spawn()#函数族,合并了fork(),exec(),可以在Windows上完成类似的工作
os.system(command)#等待结束