python--一些特性

可以用附属下表来取出人末尾向前的数组,不像其它语言需要先计算长度等等,例子如下:

>>> a = [1,2,3,4,5]

>>> print(a[-1])
5
>>> print(a[-2])
4

>>>

统计数组a元素中出现次数

>>> a = [1,2,2,3,3,3,4,4,5]
>>> from collections import Counter
>>> print (Counter)
<class 'collections.Counter'>
>>> Counter(a)

#统计数组a中出现次数最多的元素,其中3出现3次,2出现2次,4出现2次,1出现1次,5出现1次

Counter({3: 3, 2: 2, 4: 2, 1: 1, 5: 1})

#统计数组a中出现最多的元素以及次数

>>> print(Counter(a).most_common(1))
[(3, 3)]

#统计数组a中出现最多的前两名的元素以及次数

>>> print(Counter(a).most_common(2))
[(3, 3), (2, 2)]

#统计数组a中元素以及出现的次数,大小排列

>>> print(Counter(a).most_common())
[(3, 3), (2, 2), (4, 2), (1, 1), (5, 1)]
>>>


print 输出 hello world ,一种直接用逗号连接,一种用加号直接连接

>>> print('lello' , ' world')
lello  world
>>> print('lello' + ' world')
lello world

关于输入

a = input("请输入您的信息:")
print("My input is " , a)

============== RESTART: C:\Users\Administrator\Desktop\ceshi.py ==============
请输入您的信息:siyecao
My input is  siyecao
>>>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值