当前位置: 首页 > news >正文

python类的属性、方法、静态方法、静态方法类内部的调用、直接调用与实例化调用

'''
设计者:ISDF工软未来
版本:v1.0
日期:2024/3/4
'''class Restaurant:'''餐馆类'''def __init__(self,restaurant_name,cuisine_type):#类的属性self.restaurant_name = restaurant_nameself.cuisine_type = cuisine_type# self.stregth_level = 0def describe_restaurant(self):'''描述餐厅'''print(f'餐厅名字是{self.restaurant_name};菜品是{self.cuisine_type}')def open_reataurant(self):'''开餐厅'''print(f'{self.restaurant_name}餐厅正在营业')'''静态方法'''@staticmethoddef restaurant(a,b):print(a+b)'''类方法'''@classmethoddef myrestaurant(cls):Restaurant.restaurant(20,40)  #类对象调用静态方法def mynerestaurant(self):self.restaurant(50,60)   #类实例对象调用静态方法def main():'''主函数'''restaurant_name = input("请输入餐厅名称:")cuisine_type = input("请输入菜品名字:")#实例化restauranteg1=Restaurant(restaurant_name,cuisine_type)restauranteg1.describe_restaurant()restauranteg1.open_reataurant()Restaurant.restaurant(100,200)restauranteg1.restaurant(100,200)restauranteg1.myrestaurant()restauranteg1.mynerestaurant()if __name__ == '__main__':main()
http://www.lryc.cn/news/310441.html

相关文章:

  • haproxy集成国密ssl功能[下]
  • C++自学精简实践教程
  • 每日一题——LeetCode1572.矩阵对角线元素的和
  • mysql 常用命令练习
  • QT6 libModbus 用于ModbusTcp客户端读写服务端
  • 飞桨(PaddlePaddle)Tensor使用教程
  • 数据结构c版(3)——排序算法
  • 《Spring Security 简易速速上手小册》第5章 高级认证技术(2024 最新版)
  • 【七】【SQL】自连接
  • C语言while 与 do...while 的区别?
  • RK3568平台开发系列讲解(基础篇)内核错误码
  • 点云从入门到精通技术详解100篇-基于点云网络和 PSO 优化算法的手势估计(续)
  • 设计模式(十一)策略模式
  • Java 计算某年份二月的天数
  • unity 数学 如何计算线和平面的交点
  • Mysql DATETIME与TIMESTAMP的区别
  • hadoop基础
  • 2024目前三种有效加速国内Github
  • 2024高频前端面试题 HTML 和 CSS 篇
  • LeetCode 100231.超过阈值的最少操作数 I
  • Pygame教程01:初识pygame游戏模块
  • HTML和CSS (前端共三篇)【详解】
  • Linux——进程控制(二)进程等待
  • 多线程导入excel
  • 设计模式(十五)状态模式
  • Java基于SpringBoot的在线文档管理系统的设计与实现论文
  • 突破编程_C++_STL教程( list 的高级特性)
  • Scratch 第十六课-弹珠台游戏
  • 对简单工厂模式、工厂方法模式的思考
  • 【详识JAVA语言】面向对象程序三大特性之二:继承