一个构建指定坐标轴在默认点(0,0)的构造方法《python语言程序设计》2018版--第8章17题第2部分

书接上文,我们构建返回默认坐标的构造方法

直接设计默认返回0,0的方法

python 复制代码
class Point: #增加返回x,y坐标

class Point:  # 增加返回x,y坐标

    def __init__(self, x, y):
        self.__x = x
        self.__y = y

    def getX(self):
        return self.__x

    def getY(self):
        return self.__y

    def setX(self, x):
        self.__x = x

    def setY(self, y):
        self.__y = y

    def printMessage(self):
        print(f"点的x坐标{self.__x},y坐标{self.__y}")

    def resetToOriginX(self):
        self.__x = 0

    def resetToOriginY(self):
        self.__y = 0


def main():
    x = 100
    y = 100
    test1 = Point(x, y)  # 设置第一个输入
    test1.printMessage()
    test1.resetToOriginX()
    test1.resetToOriginY()
    test1.printMessage()

main()
相关推荐
孟健1 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞3 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽6 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程10 小时前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪10 小时前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook11 小时前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪1 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽1 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战1 天前
Pydantic配置管理最佳实践(一)
python