为了账号安全,请及时绑定邮箱和手机立即绑定
L = [75, 92, 59, 68, 99]
sum = 0
for i in L:
sum += i
print(sum)
print(sum/5)
print(sum/len(L))
age = 2
if age>=18:
print('adult')
elif age>=6 and age<18:
print('teenager')
elif age>=3 and age<6:
print('kid')
else:
print('baby')
age =30
if age<18:
print('teenager')
else:
print('adult')
age = 19
if age>18:
print('adult')
print('dondonqiang age {}'.format(age))
else:
print('minor')
template = '{l} {i} {s}, {y} {n} {p}'
l = 'Life'
i = 'is'
s = 'short'
y = 'you'
n = 'need'
p = 'Python'
result = template.format(l,i,s,y,n,p)
print(result)

result = template.format(l='Life',i='is',s='short',y='you',n='need',p='Python')
print(result)
template = '{}'
con = 'Life is short,you need Python'
result = template.format(con)
print(result)

template = '{0} {1} {2},{3} {4} {5}'
result = template.format('Life','is','short','you','need','Python')
print(result)
print(r'''
"To be, or not to be": that is the question.Whether it's nobler in the mind to suffer.
''')
print("special string:',\",\,\\\,\\n,\\t")
print("special string:',\",\,\\\\,\\n,\\t")
>>> a='python'
>>> print('hello,',a or 'world')
hello, python
解释:短路运算 a or 'world',a为True结果一定为True,直接返回a
>>> b=''
>>> print('hello,',b or 'world')
hello, world
解释:python讲空字符串看作False,b or 'world',b为False,结果取决于'world',直接返回‘world’
def func(x):
if isinstance(x, list):
sum = 0
for item in x:
sum += item
return sum
elif isinstance(x, tuple):
sum = 1
for item in x:
sum *= item
return sum

L = [1, 2, 3,4]
t = tuple(L)
print(func(L),func(t))
def sub_sum(L):
a = 0
b = 0
for num in L:
if(num % 2 == 0):
a += num
else:
b += num
return b,a
L = [1,2,3,4,5,6]
print(sub_sum(L))
def square_of_sum(L):
sum = 0
for itme in L:
sum = sum + pow(itme, 2)
return sum

L = [1, 5, 10]
print(square_of_sum(L))
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
for item in s1:
if item in s2:
print(item)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for item in L:
if item in S:
S.remove(item)
print(S)
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作,灵活使用流程控制语句。

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消