基础概念:
字符类型:str() 比较大小 --从第1个开始比较
数值类型:int() 比较大小 --整个值比较
strip() --删除首尾 空白
sort() --排序-永久
sorted() --排序-临时
reverse() --倒序
len() --确定长度
lower() --转换为小写
upper() --转换为大写
title() --首字母大写
if --条件判断:
and --多条加同时成立
or --多条件至少满足一个
in --特定值包含
not in --特定值不包含
if
if - else
if - elif -else
if - elif - elif else
字典:
keys()
values()
items()
input() --输入
# while 循环
active = True
while active:
message = input("请输入:")
if message == "quit":
active =False
else:
print(message)
# map/filter/reduce()
print(list(map(lambda x: x ** 2, [1, 2, 3, 4, 5])))
print(list(map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])))
movie_people=['alex','wupeiqi','yuanhao','sb_alex','sb_wupeiqi','sb_yuanhao']
print(list(filter(lambda x:x.startswith('sb'),movie_people)))
from functools import reduce
array2 =[1,3,2]
print(reduce(lambda x,y:x*y,array2))
# 形参与实参
def build(first,last,age):
person={"first":first,"last":last}
if age:
person["age"] = age
return person
mu = build("jimi","alex",18)
print(mu)
# while 与函数
u_designs = ["IOS","Android","Phone"]
com_models = []
while u_designs:
cur_desions = u_designs.pop(0)
print("打印:"+ cur_desions)
com_models.append(cur_desions)
for com_model in com_models:
print(com_model)
# ==
def print_models(u_designs,com_models1):
# u_designs = ["IOS","Android","Phone"]
# com_models = []
while u_designs:
cur_desion = u_designs.pop()
print("打印:"+ cur_desion)
com_models1.append(cur_desion)
def show(com_models):
for com_model in com_models:
print (com_model)
u_designs = ["IOS","Android","Phone"]
com_models = []
print_models(u_designs,com_models)
show(com_models)
from pizza import make_pizza as mp --as 指定别名
形参指定默认值时,等号两边不要有空格
def function_name(parameter_0,parameter_1="default value")