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)