python与数据类型相关的内置函数

字符串内置函数

s = 'hello world'
s = s.capitalize() #字符串首字母大写
print(s)
s = s.replace('world', 'binbin')  #替换
print(s)
i = '192.168.1.1'
i = i.split('.')  #以'.'分隔
print(i)
s = s.center(40, '*') #以为中心
print(s)

序列内置函数

def f(x):
    if x > 5:
        return True
l = range(10)
filter(f, l) #结合函数和序列过滤处理

def f(x):
    if x % 2 == 0:
        return True
l = range(10)
filter(f, l)
print(filter(f, l))  #函数与列表过滤出列表中的偶数

 

posted @ 2016-07-20 16:55  tan·滨  阅读(38)  评论(0)    收藏  举报