首页 飞桨领航团 帖子详情
【AI达人养成营】个人部分笔记demo
收藏
快速回复
飞桨领航团 文章学习资料 252 0
【AI达人养成营】个人部分笔记demo
收藏
快速回复
飞桨领航团 文章学习资料 252 0

#这是一份笔记

def sum(a):
a[0] = 20
print("a = ",a)

c = [1,2,3]

sum(c.copy())
print("c =",c)
#a = [20, 2, 3]
#c = [20, 2, 3]
#如果不想改变c原来的值,用 sum(c[:]) 或者sum(c.copy())

#--------------
def sum(*nums):
result = 0
for n in nums :
result += n
print("result =",result,type(nums))

print(sum())
print(sum(1,2,3))
'''
这里*a表示元组类型,可传入多个值进去
带星号只能有一个,位置随机,sum(a,*b,c)
'''
#---------------
a = 5
print(id(a))
a = 6
print(id(a))
a.append(6)
print(id(a))

#---------------
'''
字典
组名={key:value}
访问:组名['key']=value ,改值或添加
set集合
s ={1,1,2,3,5} 这里的key不能重复
'''

#------------------
'''
找位置,find,index
'and' in article 判断有没有

my_string = 'hello_word'
my_string.startwith('hello') 判断有没有 % endwith

split分割
replace替换 .replace('1,'2')
strip 是字符串规整
my_string = ' hello_world\n'
my_string.strip() = 'hello_word'

name = '小明';score = 85;height = 77.2;
print('HEllo,%s,%d,%0.2f' %(name,score,height))
print('Hello,{},{d},{.2f}' .format(name,score,height))
#print(f"Hello,我是{name},我分{score},体重{heightt:0.3f}")

print('Hello,{0},{1:d},{2:.2f}' .format('小明',85,77.2))
print('Hello,{name:},{score:d}分,{height:.2f}' .format(name = '小明',score = 85, height = 77.2))

print('%d %%' %(a*100)) #输出为百分之多少
'''

#-------------------
for i in range(len(list1)):
list1[i] += 1

[n+1 for n in list1]
#1-10之间做有数的平方 构成的字符串列表
[str(n+1)**2 for n in range(10)]
['app_%s'%n for n in list1]
[f'app__{n}' for n in list1]

[n for n in list1 if n%2==0]
[n for n in list1 if n%2==1]

[m+n for m in 'ABC' for n in 'ZXY']

0
收藏
回复
在@后输入用户全名并按空格结束,可艾特全站任一用户