1.函数
1.1 max()函数
见收藏夹
x,y,z=eval(input('input 3 numbers:'))
print(max(x,y,z,4))
a=max(x,y,z)
print(a)
>>>
input 3 numbers:1,2,3
4
3
1.2 math库中的degrees()
Definition : degrees(...)
Type : Function of math module
Convert angle x from radians to degrees.
x=2
degrees(x)
>>> 114.59155902616465
2.未命名
2.1 序列解包
li=[[12,4],[5]]
print(*li)
>>>[12,4] [5]
#也可以是tuple,list
x=(12,3,'s',(0,2))
print(*x)
>>>
12 3 s (0,2)
2.2 count&dictionary
s=input('请输入字符串:')
s=s.upper()
list=[]
for c in s:
if c not in list:
list.append(c)
print(list)
dict1={}
for j in list:
dict1[j]=s.count(j)
print(dict1)
count前面要有 对象.count('子字符串')
返回为整数
2.3 list用法
list可以直接相加,和string一样
2.4 tuple
注意:
不能修改元组的元素
tup2 = (1, 2, 3, 4, 5, 6, 7 )
>>>tup2[1]=10
TypeError: 'tuple' object does not support item
但是:元组元素为对象时,可修改
>>>tup3=([1,2,3],4,5)
>>>tup3[0][1]=100
>>>tup3
Out[33]: ([1, 100, 3], 4, 5)