摘要: # 名称空间与作用域 # 1、内置名称空间:内置函数print # 2、全局名称空间:文件名字,x=1,全局变量只定义好,全局都可以用 # 3、局部名称空间:在函数内部定义y=2,y只在函数内有效 # 1和2成为全局作用域,3是局部作用域 # x=1 # def funcname(): # pass 阅读全文
posted @ 2018-03-25 21:12 森森2017 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 函数 # 函数:就是工具 # 1、内置函数print # 2、自定义函数 ''' ################## alex sb sb ################## ''' # def print_line(): # print('#'*9) # # def print_msg(): 阅读全文
posted @ 2018-03-25 21:11 森森2017 阅读(121) 评论(0) 推荐(0) 编辑
摘要: test的内容:白日不到处,青春恰自来。苔花如米小,也学牡丹开。test1的内容: hellopp王test2的内容: hello # 修改一个文件# with open("test",encoding="utf8") as f_read,open("test1",encoding="utf8",m 阅读全文
posted @ 2018-02-21 23:08 森森2017 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 网址文件py.txt内容: 测试程序: while 1: m=input("please input url:").strip() l=[] flag=False with open("C:\\Users\\user\\PycharmProjects\\py_fullstack_s4\\201803 阅读全文
posted @ 2018-02-21 23:05 森森2017 阅读(172) 评论(0) 推荐(0) 编辑
摘要: test内容: hello李杰test2内容: 国家沦陷只有山河依旧,春日的城区里荒草丛生。 # coding=utf8# 数据不要放在程序中,放文件中就等于放在磁盘中,不会丢# 流程:# 1、打开文件 open()# 2、如果对文件进行增删改查 read\write# 3、关闭文件 close() 阅读全文
posted @ 2018-02-21 23:03 森森2017 阅读(218) 评论(0) 推荐(0) 编辑
摘要: # 集合就是字典,数据类型都是set,是通过set来创建# 两个功能:1去重 2关系测试 3无序s=set([1,3,"hello"])s2={1,2,3}print(type(s))print(type(s2))print(s2)# 去重l=[1,2,2,34,56]print(set(l))# 阅读全文
posted @ 2018-02-21 23:01 森森2017 阅读(189) 评论(0) 推荐(0) 编辑
摘要: # 创建元组t=(1,2,3)t2=tuple([1,2,3])# 元组不能修改print(t[1:2])print(t[:])# 改变数据类型 list()变列表 tuple变字典print(list(t[1:2])) 阅读全文
posted @ 2018-02-21 22:58 森森2017 阅读(103) 评论(0) 推荐(0) 编辑
摘要: # 创建列表 可迭代对象:能够for循环l=[1,"hello",[4,5],{"name":"egon"}]l2=list([1,23,3]) #l2=list((1,23,3))也行l3=[1,22,3,43,43434,565,77]l4={1,23}print(l2)print(type(l 阅读全文
posted @ 2018-02-21 22:58 森森2017 阅读(93) 评论(0) 推荐(0) 编辑
摘要: # for i in seq: # 可以是序列,元组,字符串,字典# print("ok")# 两个问题:# 1、循环次数由一级元素的个数决定,下面循环3次## for item in ["hello",123,[2,3,4]]: # 可以是序列,元组,字符串,字典# print(item)## p 阅读全文
posted @ 2018-02-21 22:57 森森2017 阅读(124) 评论(0) 推荐(0) 编辑
摘要: # 拼接方法# s="hello"+" world"+" world"# 占内存 因为"hello"、" world"、" world"各在内存占一个空间,"hello"+" world"的结果也占一个空间,才到结果# print(s)# join# print("+".join(["i","am" 阅读全文
posted @ 2018-02-21 22:56 森森2017 阅读(170) 评论(0) 推荐(0) 编辑