Python之list,string,tuple,dict練習題
Python之list,string,tuple,dict練習題
#!/usr/bin/env python # -*- coding:utf8 -*- # @Time : 2017/10/30 10:11 # @Author : hantong # @File : threed_week.py import codecs #對列表排序 list = [22,4,6,8,10,334,779,234,54,666] list.sort() print(list) #寫入列表到檔案 with open("txt","w") as f: f.write('\n') f.write(str(list)) #追加反序到檔案下一行 with open('txt','r') as f: t2 = f.read() print(t2) list.reverse() with open("txt",'a') as f: f.write('\n') f.write(str(list)) print(list) #分別把string,list,tuple,sict寫入到文章中 string = 'akgnehkkd123' tuple = ('a','r','hhh','fe','hty') list = [23,'ff',456,'ghj','eryi'] dict = {'a':24,'d':56,'cd':89,'b':65} #將string寫入到txt3檔案中 with open('txt3','w') as f: f.write('\n') f.write(string) #將list寫入到txt3檔案中 with open('txt3','a') as f: f.write('\n') f.write(str(list)) #將tuple寫入到txt3檔案中 with open('txt3','a') as f: f.write('\n') f.write(str(tuple)) #將dict寫入到txt3檔案中 with open('txt3','a') as f: f.write('\n') f.write(str(dict))
相關文章
- Python 的List 和tuple,Dict,SetPython
- python中的list,tuple,set和dict(參考python文件)Python
- Python list,dict問題解答Python
- Python3學習筆記2,基本資料型別-list、tuple、set、dictPython筆記資料型別
- Python零基礎學習筆記(三十二)——list/tuple/dict/set檔案操作Python筆記
- Python中基礎資料型別(List、Tuple、Dict)的概念和用法Python資料型別
- Python中的基礎資料型別(List,Tuple,Dict)及其常用用法簡析Python資料型別
- python str dict list 轉換Python
- Python基礎:使用list & tuplePython
- java String類練習題Java
- python中的list、tuple和dictionaryPython
- python list tuple str dic series dataframePython
- Python的List vs Tuple比較Python
- 草根學Python(三)List 和 TuplePython
- python list(列表)和tuple(元組)Python
- Python中tuple和list的區別?Python基礎學習!Python
- Python中元組tuple的作用以及tuple和list的轉換Python
- Python3之字串str、列表list、元組tuple的切片操作Python字串
- python列表(list)和元組(tuple)詳解Python
- python基礎之列表list元組tuplePython
- python 切片獲取list、tuple中的元素Python
- 新手練習:Python練習題目Python
- Python 練習題Python
- Python 字典 dict 獲取索引 轉化為 listPython索引
- Python之dict的妙用Python
- Python 小練習 求list內中間數Python
- Python筆記:string,tuple,list,dictionary的區別(之二,高階用法與型別轉換)Python筆記型別
- python練習題解析Python
- Python 選列表 list 還是元組 tuple 的思考Python
- python學習:元組tuplePython
- Python順序集合之 tuplePython
- Python中tuple和list有什麼區別?Python入門!Python
- Python 內建型別 dict, list 執行緒安全嗎Python型別執行緒
- Python基礎練習題Python
- 五、python的練習題Python
- Python函式練習題Python函式
- python相關練習題Python
- python之字典(dict)基礎篇Python