1、input
获取用户输入,可以时字符串也可以是数值,返回的都是字符串
age = input('How old are you?')
age = int(age)#返回数值
name = input('What is your name?')
2、title()
str.title()
返回标准化字符串 所有单词都以大写开头
str = "this is string example....wow!!!";
print str.title();
>>> This Is String Example....Wow!!!
3、.items()
dict.items() 遍历字典
dict = {'Google': 'www.google.com', 'Runoob': 'www.runoob.com', 'taobao': 'www.taobao.com'}
print "字典值 : %s" % dict.items()
# 遍历字典列表
for key,values in dict.items():
print key,values
>>>Google www.google.com
taobao www.taobao.com
Runoob www.runoob.com
4、传参数
- 传入元组
- 传入字典
两个 星号 让Python创建一个空字典,并将所有名称–值对都封装到这个字典中去。
5、函数编写指南
- 描述性的语言,只用小写字母和下划线,不超过79字符(告诉第三者函数是干什么的)
- 函数注释
- 形参赋值等号两边不要空格。