python 之基础编程(一)

(1)利用map函数,把用户输入的不规范的英文字母变成首字母大写

#!/usr/bin/env python
#coding:utf-8
'''
author:ChenRongbo
filename:homework.py
date:7/11/17
desc:hello file
'''
def ul(str):  return str.title()
li = ['LIsten','speak','rEad',"Write"]
print map(ul,li)

(2)求积函数

#!/usr/bin/env python
#coding:utf-8
'''
author:ChenRongbo
filename:multiplity.py
date:7/11/17
desc:hello file
'''
def mul(x,y):
    return x*y
li = [1,2,3,4]
print reduce(mul,li)

(3)统计单词数

#!/usr/bin/env python
#coding:utf-8
'''
author:ChenRongbo
filename:wc-word.py
date:7/11/17
desc:hello file
'''
str = 'I like qpy very much'
def wc():
    return len(str.split())
print wc()

猜你喜欢

转载自blog.csdn.net/bittersweet0324/article/details/74990150