Python&Hint

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)

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值