python面试题

1.python简介?

答:
Python是解释型的语言:Python是在运行时被解释处理。你不需要在执行前编译程序。这类似于Perl和PHP。
Python是交互式的: 实际上,可以在 Python 提示和解释直接交互来编写程序。
Python是面向对象:Python支持面向对象式或编程的对象中封装代码的技术。

2.   python特点?

答:广泛的标准库、交互式模式、可扩展、易于阅读、易于维护;

3.    随机生成100个字符,统计字符出现的次数?

import string
import random
mstr=string.ascii_letters+string.digits+string.punctuation
print(mstr)
#从mstr字符串随机抽取100个字形成列表
mli=[random.choice(mstr) for i in range(100)]
d={}
for c in mli:
    d[c]=d.get(c,0)+1
re=sorted(d)
#通过sorted排序函数后,返回的是key集合的排序后的列表
for k in re:
    print(k,d.get(k),sep=":",end="\t\t")

4.    统计字符出现的最多次数

#导入Counter
from collections import Counter
#通过字符串实例化Counter对象
co=Counter(mres)
# print(type(co),co)
# 遍历Counter对象
for it in co.items():
    print(it)
#通过出现次数最多的字
v=co.most_common(3)
print(v)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值