蓝绝

博客园 首页 新随笔 联系 订阅 管理
  232 随笔 :: 1 文章 :: 0 评论 :: 25926 阅读

随笔分类 -  python基础学习 01 图解Python语法

1 2 3 4 5 下一页

摘要:import os.path print('1.',os.path.abspath('demo13.py')) #获取文件或目录绝对路径 print('2.',os.path.exists('demo13.py'),os.path.exists('demo18.py')) #判断文件和目录是否存在 阅读全文
posted @ 2022-10-05 21:38 蓝绝 阅读(34) 评论(0) 推荐(0) 编辑

摘要:#目录操作 #os模块是Python内置的与操作系统功能和文件系统相关的模块,该模块中的语句的执行结果通常与操作系统有关,在不同的操作系统上运行,得到的结果可能不一样。 #os模块与os.path模块用于对目录或文件进行操作 #os模块与操作系统相关的一个模块 import os os.system 阅读全文
posted @ 2022-10-04 20:35 蓝绝 阅读(60) 评论(0) 推荐(0) 编辑

摘要:#with语句确保,不论是否运行错误都确保文件关闭, with open('a.txt','r') as file: print(file.read()) # MyContentMgr实现了特殊方法__enter__(),__exit__()称为该类对象遵守了上下文管理器协议该类对象的实例对象,称为 阅读全文
posted @ 2022-10-04 20:02 蓝绝 阅读(12) 评论(0) 推荐(0) 编辑

摘要:# 读,输出 read(), read([size]) , readline(), readlines() file = open('a.txt','r') print('输出文本所有内容',file.read()) # 输出文本所有内容 file.close() file = open('a.tx 阅读全文
posted @ 2022-10-04 18:59 蓝绝 阅读(43) 评论(0) 推荐(0) 编辑

摘要:file=open('a.txt','w') #a.txt 如果没有就会创建新的文件 file.write('python') #文件写入python file.close() file=open('a.txt','a') # a 文件追加内容 file.write('python1') file. 阅读全文
posted @ 2022-10-03 22:05 蓝绝 阅读(49) 评论(0) 推荐(0) 编辑

摘要:#pycharm 新建文件或其他文件默认为 UTF-8 格式,如果新建文件中有中文,就会读取失败,可把文件另存为其他格式(gbk) file=open('a.txt','r') #打开读取文件#需手动新建a.txt.文件 print(file.readline()) #输出读取文件内容 file.c 阅读全文
posted @ 2022-10-03 21:03 蓝绝 阅读(32) 评论(0) 推荐(0) 编辑

摘要: 阅读全文
posted @ 2022-10-03 20:17 蓝绝 阅读(22) 评论(0) 推荐(0) 编辑

摘要: 阅读全文
posted @ 2022-09-26 21:24 蓝绝 阅读(33) 评论(0) 推荐(0) 编辑

摘要:#cmd 安装第三方模块 #pycharm调用第三方模块 import schedule #导入第三方模块 import time '''每3秒输出 ’哈哈--‘ 休眠1秒,循环进行''' def job(): print('哈哈 ') schedule.every(3).seconds.do(jo 阅读全文
posted @ 2022-09-26 21:22 蓝绝 阅读(19) 评论(0) 推荐(0) 编辑

摘要: 阅读全文
posted @ 2022-09-26 21:02 蓝绝 阅读(28) 评论(0) 推荐(0) 编辑

摘要:#目录和包的区别 #模块的导入的2种方式 #模块1 module_A a=10 #模块2 moduleB b=100 #模块3 名称:demo55 '''使用import方式进行导入时,只能跟包名或模块名''' import chap1.pageage1.module_A as ma #ma为别名。 阅读全文
posted @ 2022-09-25 11:52 蓝绝 阅读(16) 评论(0) 推荐(0) 编辑

摘要:#加上 if __name__ == '__main__': 判断是否在当前模块中运行,如果是则输出。如果是其他模块调用该模块运行,则 if __name__ == '__main__': 下面的代码不会运行。 #模块1 名称:calc2 def add(a,b): return a+b if __ 阅读全文
posted @ 2022-09-25 10:58 蓝绝 阅读(28) 评论(0) 推荐(0) 编辑

摘要:#1.1自定义模块 #1.1.1创建模块 #1.1.1.1新建一个.py文件,名称尽量不要与Python自带的标准模块名称相同 # 1.1.2创建模块 # 1.1.2.1 导入模块 第一种 import 模块名称 [as 别名] #导入整个模块 第二种 form 模块名称 import 函数/变量/ 阅读全文
posted @ 2022-09-25 10:35 蓝绝 阅读(59) 评论(0) 推荐(0) 编辑

摘要: 阅读全文
posted @ 2022-09-25 09:43 蓝绝 阅读(92) 评论(0) 推荐(0) 编辑

摘要:#浅拷贝示意图 #深拷贝示意图 class CPU: pass class Disk: pass class Computer: def __init__(self,cpu,disk): self.cpu=cpu self.disk=disk #(1)变量的赋值 cpu1=CPU() cpu2=cp 阅读全文
posted @ 2022-09-24 21:26 蓝绝 阅读(36) 评论(0) 推荐(0) 编辑

摘要:'''__new__用于创建对象, __init__把创建的对象初始化''' class Person(object): def __new__(cls, *args, **kwargs): print('__new__被调用执行了,cls的id值为{0}'.format(id(cls))) obj 阅读全文
posted @ 2022-09-24 20:31 蓝绝 阅读(16) 评论(0) 推荐(0) 编辑

摘要:'''#两个整数类型的对象的相加操作''' a=20 b=100 c=a+b #两个整数类型的对象的相加操作 d=a.__add__(b) print(c) print(d) '''字符串等相加用 类中设置__add__的方法''' class Student: def __init__(self, 阅读全文
posted @ 2022-09-24 20:26 蓝绝 阅读(21) 评论(0) 推荐(0) 编辑

摘要:class C(A,B): def __init__(self,name,age): self.name=name self.age=age class D(A): pass #创建C类的对象 x=C('Jack',20) #x是C类型的一个实例对象 print('1.',x.__dict__) # 阅读全文
posted @ 2022-09-24 20:09 蓝绝 阅读(16) 评论(0) 推荐(0) 编辑

摘要:class Student: def __init__(self,name,age): self.name=name self.age=age def __str__(self): #object中有__str__()方法,用于对于 ‘对象的描述’ return '我的名字是{0},今年{1}岁'. 阅读全文
posted @ 2022-09-18 13:20 蓝绝 阅读(9) 评论(0) 推荐(0) 编辑

摘要:class Student: def __init__(self,name,age): self.name=name self.age=age def __str__(self): #object中有__str__()方法,用于对于 ‘对象的描述’ return '我的名字是{0},今年{1}岁'. 阅读全文
posted @ 2022-09-17 20:13 蓝绝 阅读(9) 评论(0) 推荐(0) 编辑

1 2 3 4 5 下一页
点击右上角即可分享
微信分享提示