tuple 元组(创建后不能修改)

tuple = "cat","dog","tiger","human"
print(tuple) def fun(x):
return x,x*2 print(type(fun(3))) for x,y in ((2,0),(2,5),(3,8)):
print(x+y)

set 集合

S = {435,"BAT",(25,"CS"),435}
print(S) W = set("apple")
print(W) V = set(("cat",4,"apple"))
print(V)

list 列表

ls = [423,"BAT",[10,"CS"]]
print(ls[2][1][1]) vlist = list(range(5))
print(vlist) print("YES") if 2 in vlist else print("NO") lss = [52,36,95,78]
print(sorted(lss))
print(lss)

字典

sets = {23,35}
print(type(sets))
setss = {34:23,33:22,23:32} for a in setss.keys():
print(a) ls = setss.items()
print(ls) for key in setss:
print(setss[key])

计算平均数,和标准差

import math

def inputs() :
nums = []
x = input()
while x != "":
nums.append(int(x))
x = input()
return nums ls = inputs()
print(ls) def mean(numbers):
s = 0
for num in numbers:
s += num
return s / len(numbers) def dev(numbers,means):
sdev = 0
for num in numbers:
sdev += (num-means)**2
return math.sqrt(sdev/(len(numbers)-1)) print(dev(ls,mean(ls)))

统计词频(哈利波特1)

txt = open("1.Harry Potter and the Sorcerer's Stone.txt","r").read()
txt = txt.lower() for ch in '",!-?;.`':
txt = txt.replace(ch," ")
#print(txt) ls = txt.split()
print(ls) maps = {}
for str in ls:
maps[str] = maps.get(str,0) + 1 item = list(maps.items()) cnt = 1
for a in item :
print(a,end=" ")
if cnt % 10== 0:
print("")
cnt+=1
print("") item.sort(key=lambda x:x[1],reverse=True) for i in range(10):
word ,count = item[i]
print(word,count)

Python语言程序设计基础(6)—— 组合数据类型的更多相关文章

  1. Python语言程序设计基础(3)—— 基本数据类型

    天天向上 dayup,dayfactor = 1.0,0.01 for i in range(365): if i % 7 in [6,0]: dayup = dayup*(1-dayfactor) ...

  2. python语言程序设计基础 习题 天天向上的力量(math.pow)

    实例1: 一年365天,,以第一天的能力值为基数1.0,当好好学习时能力值相比前一天提高1%,没有学习时能力值相比前天要降低1%,每天努力和每天放任,一年下来的能力值相差多少? 解析: 如果每天都好好 ...

  3. Python语言程序设计基础(4)—— 程序的控制结构

    PM2.5 pm = eval(input()) if pm>=75: print("空气存在污染") else : print("空气没有污染") pr ...

  4. python语言程序设计基础(嵩天)第四章课后习题部分答案

    p121: *题4.1:猜数字游戏.在程序中预设一个0~9之间的整数,让用户通过键盘输入所猜的数,如果大于预设的数,显示“遗憾,太大了!”:小于预设的数,显示“遗憾,太小了!”,如此循环,直至猜中该数 ...

  5. python语言程序设计基础(嵩天)第二章课后习题

    p56: *2.1 实例1的修改.改造实例代码1.1,采用eval(input(<提示内容>))替换现有输入部分,并使输出的温度值为整数. 源代码: TempStr=input(" ...

  6. Python语言程序设计基础(7)—— 文件和数据格式化

    返回字符串 file = input() #返回字符串 fo = open(file,"r").read(6) print(fo) 返回列表形式 file = input() fo ...

  7. Python语言程序设计基础(5)—— 函数和代码复用

    lambda sum = lambda x,y : x + y print(sum(3,3),type(sum)) 默认参数 def prints(str,times = 2) : print(str ...

  8. Python语言程序设计基础(2)—— Python程序实例解析

    温度转换 def tempConvert(ValueStr): if ValueStr[-1] in ['F','f']: ans = (eval(ValueStr[0:-1]) - 32)/1.8 ...

  9. Python语言程序设计基础(1)—— 程序设计基本方法

    Everybody in this country should learn how to program a computer,because it teaches you how to think ...

随机推荐

  1. Mercedes BENZ C5 SD Connect Xentry Tab Kit Technical Support

    Why MB Star Diagnostic tool is so well-received by thousands of users, its technology and quality is ...

  2. VUE-CLI 设置页面title

    router > index.js { path: '/worklist', name: 'worklist', component: worklist, meta: {title:'维修工列表 ...

  3. Oracle RAC集群添加节点

    一,节点环境 所有节点分发/etc/hosts,这里我添加两个节点,一个是上次删除的节点,另一个是什么都没有的节点,尝试添加 服务器介绍什么的都在这hosts文件了,大家自己琢磨下 [grid@nod ...

  4. Oracle 基础系列之1.2 oracle的基本使用

    在1.1的安装过程完成之后,进入第二部分,oracle的基本使用,在使用前,首先测试下,oracle是否安装成功,以及检查oracle的关键服务时候开启 1.首先测试下,oracle是否安装成功 打开 ...

  5. query的参数解析

    SQLiteDatabase dbInstance;Cursor cursor = dbInstance.query(String table,String []Columns, String sel ...

  6. java url生成二维码保存到本地

    http://blog.sina.com.cn/s/blog_5a6efa330102v1lb.html http://blog.csdn.net/about58238/article/details ...

  7. pat1012. The Best Rank (25)

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  8. pat1011. World Cup Betting (20)

    1011. World Cup Betting (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Wit ...

  9. FZU 1922——非主流——————【技巧题】

    非主流 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status P ...

  10. js event事件绑定的方法

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...