随笔分类 - python
摘要:curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" python get-pip.py pip install paramiko
阅读全文
posted @ 2020-09-18 16:57
才华配得上梦想
摘要:import pygame class GameSprite(pygame.sprite.Sprite): """飞机大战游戏精灵""" def __init__(self, image_name, speed = 1): # 调用父类的初始化方法 super().__init__() # 定义对象
阅读全文
posted @ 2019-08-30 15:26
才华配得上梦想
摘要:import pygame pygame.init() # 创建游戏窗口 screen = pygame.display.set_mode((480, 700)) # 加载backgroud.png创建背景 bg = pygame.image.load("./images/background.pn
阅读全文
posted @ 2019-08-29 08:24
才华配得上梦想
摘要:import pygame pygame.init() # 创建游戏窗口 screen = pygame.display.set_mode((480, 700)) # 加载backgroud.png创建背景 bg = pygame.image.load("./images/background.pn
阅读全文
posted @ 2019-08-28 12:21
才华配得上梦想
摘要:python -m pygame.examples.aliens import pygame pygame.init() # 编写邮箱代码 print("游戏代码") pygame.quit() import pygame # 定义hero_rect矩形描述英雄的位置和大小 hero_rect =
阅读全文
posted @ 2019-08-27 21:17
才华配得上梦想
摘要:1.安装Python3.6 安装准备 编译安装 将默认Python修改为Python3.6,并为其创建软连接 修改yum使用的原python的配置文件 2.安装pip3 安装pip依赖库 如果安装上述依赖库出现以下报错:Delta RPMs disabled because /usr/bin/app
阅读全文
posted @ 2019-08-27 19:28
才华配得上梦想
摘要:文本文件 二进制文件 # 打开文件 file = open("README") # 读取文件 text = file.read() print(text) # 关闭文件 file.close() # 打开文件 try: file = open("README") except Exception a
阅读全文
posted @ 2019-08-27 08:48
才华配得上梦想
摘要:from distutils.core import setup setup(name=“hm_message”, # 包名version=“1.0”, # 版本description=“itheima’s 发送和接收消息模块”, # 描述信息long_description=“完整的发送和接收消息
阅读全文
posted @ 2019-08-27 07:58
才华配得上梦想
摘要:from . import send_message from . import receive_message def receive(): return "这是来自100xx的短信" def send(text): print("正在发送%s" % text) import hm_message
阅读全文
posted @ 2019-08-26 19:47
才华配得上梦想
摘要:import hm_01_测试模块1 import hm_02_测试模块2 hm_01_测试模块1.say_hello() dog = hm_01_测试模块1.Dog() print(dog) hm_02_测试模块2.say_hello() cat = hm_02_测试模块2.Cat() print
阅读全文
posted @ 2019-08-23 21:33
才华配得上梦想
摘要:def demo1(): return int(input("请输入一个整数")) def demo2(): return demo1() # 利用异常的传递性 ,在主程序捕获异常 try: print(demo2()) except Exception as result: print("未知错误
阅读全文
posted @ 2019-08-23 20:50
才华配得上梦想
摘要:捕获异常 try: .. except: ... try: num = int(input("请输入整数:")) except: print("请输入整数") 捕获未知错误 try:
阅读全文
posted @ 2019-08-22 23:09
才华配得上梦想
摘要:class MusicPlayer(object): # * 元组 ** 字典 def __new__(cls, *args, **kwargs): # 使用类名创建对象,new方法会被自动调用 print("创建对象,分配空间") # 2 为对象分配空间 instrance = super()._
阅读全文
posted @ 2019-08-22 21:19
才华配得上梦想
摘要:class Game(object): # 定义一个类属性,来记录游戏的历史最高分 top_score = 10 def __init__(self, player_name): self.player_name = player_name @staticmethod def show_help()
阅读全文
posted @ 2019-08-21 22:26
才华配得上梦想
摘要:不同的子类对象调用相同的父类方法,产生不同结果 可以增加代码的灵活度 以继承和重写父类方法为前提 是调用方法的技巧,不会影响到类的内部设计 class Dog(object): def __init__(self, name): self.name = name def game(self): pr
阅读全文
posted @ 2019-08-21 21:00
才华配得上梦想
摘要:单继承 封装根据职责将属性和方法封装到一个抽象的类 继承可以实现代码的重用,相同的代码不需要重复编写 1)语法 class 类名(父类名): pass 子类继承自父类,可以直接使用父类已经封装好的方法 子类应该根据职责,封装子类特有的属性和方法 class Animal: #def __init__
阅读全文
posted @ 2019-08-21 20:59
才华配得上梦想
摘要:01 封装 将属性和方法封装到一个抽象的类中 外界使用类创建对象,然后让对象调用方法 对象方法的细节都被封装在类的内部 02 晓明爱跑步 需求: 1 晓明体重 75.0公斤 2 晓明每次跑步会减肥0.5公斤 3 晓明每次吃东西体重会增加1公斤 name weight __init__(self, n
阅读全文
posted @ 2019-08-20 22:16
才华配得上梦想
摘要:dir 内置函数 变量,数据,函数都是对象 In [9]: def demo(): ...: """这个是测试函数""" ...: print("123") ...: In [10]:dir(demo) #使用内置函数dir传入标志符/数据,可以查看对象内的所有属性和方法 In [10]: demo
阅读全文
posted @ 2019-08-19 22:38
才华配得上梦想

浙公网安备 33010602011771号