为了账号安全,请及时绑定邮箱和手机立即绑定
In [13]:

def vcb(**c):
namess = c['names']
genderss = c['genders']
agess = c['ages']
index = 0
for name in namess:
gender = genderss[index]
age = agess[index]
index += 1
print(name + ' is a ' + gender + ' of '+ age)
#输入时注意列表里面的元素都为字符串即可
In [9]:

def vcb(names,genders,ages):
index = 0
for name in names:
gender = genders[index]
age = ages[index]
index += 1
print(name + ' is a ' + gender + ' of '+ age)
#输入时注意列表里面的元素都为字符串即可
def hancan(x):
listhe = 0
tuplehe = 1
if isinstance(x,list):
for i in x:
listhe += i
return listhe
elif isinstance(x,tuple):
for j in x:
tuplehe *= j
return tuplehe
else:
return '数据类型有误'
或运算下
a是字符串,判断为ture 返回a
b是空字符串判断为false,结果取决于world,返回world
输出hello Python
hello world
In [45]:

a =[1,2,3,4,5,6,7,8,9,10]
b =set([1,3,5,7,9,11])
for j in a:
if j in b:
b.remove(j)
else:
b.add(j)
continue
print(b)
In [17]:


for i in q:
j = i.lower()
q.add(j)
print(q)
if j in q:
break
list 合并函数!!
extend
列表合并函数 exterd
a =['Ab','Ac']
b =lower(a)
a.exterd(b)
print(a)
==>['Ab','Ac','ab','ac']
T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))

for i in T:
print(i)
其实这就是集合的差集运算,个人觉得下列代码更为优雅

L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
L2S = set(L)
res = L2S - S
print(res)
# Enter a code
def square_of_sum(L):
result=0
for num in L:
result=result+num*num
return result
l=[1,2,3,4]
print(square_of_sum(l))
# Enter a code
L=[]
i=1
while i<101:
L.append(i*i)
i=i+1
print(sum(L))
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])

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

微信扫码,参与3人拼团

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

友情提示:

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消