#输入逗号分割的两个数字--input输入的内容,默认为字符类型
x,y =input("input:").split(",")
print(x,y)
#输入的多个数据转换成数值列表
# lst = list(eval(input("输入数据,转化成数值:")))
lst = ["3","6","7","2","4"]
lsts = list(eval(item) for item in lst)
print(lsts)
#print("your string here.",sep=",",end="")输出的行尾默认跟一个换行符(\n)--可指定空格--一行输出不换行。sep指定输出内容分隔符:如逗号。
for i in range(10):
print(i)
for i in range(10):
print(i,end=" ")
print()
chars ="0123"
bb= "456789"
cc = "123abc"
print(chars,bb,cc,sep=",")
print()
#基本函数 map() filter() reduce()和lambda()算子-operater
#using map()
lst=[7,4,8,3,2,9]
x = list(map(lambda x:x**2,lst)) #对列表每一个对象应用lambda函数惊醒计算
print(x)
#字母变大写
lst = ["huawei","apple"]
#lst1 = map(upper,lst) #error when running
lst1 = map(lambda word : word.upper() ,lst)
#print(lst1) can not get the result
for i in lst1:
print(i,end =" ")
print()
#using filter()
lst = [2,3,4,5,6,7,8,9]
y = list(filter(lambda x:x%2==0,lst))
print(y)
print()
#using reduce()
from functools import reduce
lst=[1,2,3,4,5]
lst3 = reduce(lambda x,y:x+y,lst) #递归计算
'''
1:x+y 1+2=3
2:x+y 3+3=6
3:x+y 6+4=10
4:x+y 10+5=15
'''
print(lst3)
#output:15
print("合计:",sum(lst)) #参照reduce()