摘要: 用刚学的eval()方法对代码进行了改进,感觉发现了新大陆 阅读全文
posted @ 2018-05-10 19:32 Octopuslnlzy 阅读(193) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' #-----------定义函数---------- def func1(): "test1" print('in the func1') return 0 #-----------定义过程---------- def func2(): "test2" ... 阅读全文
posted @ 2018-05-10 19:30 Octopuslnlzy 阅读(5072) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' #----------函数位置参数和关键字参数---------- def test(x,y): #此处的 x,y为形参 print(x) print(y) test(1,2) #位置参数调用-此处的 1,2为实参,且与形参一一对应 test(y=2,x=1) ... 阅读全文
posted @ 2018-05-10 19:30 Octopuslnlzy 阅读(1042) 评论(0) 推荐(0) 编辑
摘要: 由于目前暂时还未学习到python关于数据处理的模块方面的知识,且刚好最近朋友发来一份坐标数据文件(txt格式),让我帮他对其进行筛选, 因此利用了最近刚学过的python文件处理操作以及以前所学的基础知识,用比较笨的方法勉强写了出来。 最终实现了打印出符合目标要求的具体坐标以及总个数 需求:筛选出 阅读全文
posted @ 2018-05-08 19:07 Octopuslnlzy 阅读(4748) 评论(0) 推荐(0) 编辑
摘要: ''' #-----------文件修改---------- f=open("test_1",'r',encoding="utf-8") f2=open("test_1_1",'w',encoding="utf-8") for line in f: if "肆意的快乐等我享受" in line: line=line.replace("肆意的快乐等我享受","肆意的快乐等张... 阅读全文
posted @ 2018-05-08 19:02 Octopuslnlzy 阅读(215) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- f=open("test_1",'r',encoding="utf-8") #'r'代表读文件 ''' #----------读文件---------- print(f.tell()) #tell计数按照字符来计数 print(f.read(5)) #读前5个字符,注意此时文件指针已经到... 阅读全文
posted @ 2018-05-08 19:01 Octopuslnlzy 阅读(285) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- #集合性质:需要传入一个list,且不含重复的元素,无序 list_1=[1,2,1,4,5,8,3,4,6,9,4,2,7,0,6,3,2] str_1='abcdefga' #-----------去重---------- list_1=set(list_1) #去除重复元素 print... 阅读全文
posted @ 2018-05-07 20:30 Octopuslnlzy 阅读(441) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- #key-value #dict 无序,无下标,不需要下标,因为有key stu={ 'stu001':"zhang yu", 'stu002':"ma hong yan", 'stu003':"zhang guo bin", 'stu004':"sha chun h... 阅读全文
posted @ 2018-05-05 15:45 Octopuslnlzy 阅读(344) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- province={ '江苏省':{ '南京市':['秦淮区','玄武区','栖霞区'], '苏州市':['姑苏区','虎丘区','吴中区'], '无锡市':['滨湖区','惠山区','锡山区'] }, '浙江省':{ ... 阅读全文
posted @ 2018-05-05 14:37 Octopuslnlzy 阅读(214) 评论(0) 推荐(1) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' names=['zhangyu','mahongyan','zhangguobin','shachunhua'] -----增----- names.append('zhangzhongjian') #在list尾部插入一个元素 names.insert(1,'aaa') #在list... 阅读全文
posted @ 2018-05-04 20:25 Octopuslnlzy 阅读(433) 评论(0) 推荐(0) 编辑