当前位置:网站首页>__ str__ Output class
__ str__ Output class
2022-07-25 06:40:00 【You in Yangzhou】
class Cat:
""" Define a cat class """
def __init__(self, new_name, new_age):
""" After creating the object Automatically called , It completes the function of object initialization """
# self.name = " Tom "
# self.age = 20
self.name = new_name
self.age = new_age # It is an attribute in an object , Store... In an object , That is, as long as the object still exists , Then this variable can be used
# num = 100 # It's a local variable , When this function is executed , There is no space for this variable , Therefore, other methods cannot use this variable
def __str__(self):
""" Returns the description of an object """
# print(num)
return " The name is :%s , Age is :%d" % (self.name, self.age)
def eat(self):
print("%s Eating fish ...." % self.name)
def drink(self):
print("%s Drinking coke ..." % self.name)
def introduce(self):
# print(" The name is :%s, Age is :%d" % ( Tom's name , Tom's age ))
# print(" The name is :%s, Age is :%d" % (tom.name, tom.age))
print(" The name is :%s, Age is :%d" % (self.name, self.age))
# Created an object
tom = Cat(" Tom ", 30)
print(tom)
边栏推荐
- “font/woff“ and “font/woff2“ in file “mime.types“
- 大话西游服务端启动注意事项
- ArgoCD 用户管理、RBAC 控制、脚本登录、App 同步
- The code of Keil and Si compiler is not aligned??
- EXCEL
- Easy to use code statistics tool
- 探讨影响自动化测试成败的重要因素
- The most comprehensive multi-threaded application tutorial - summary in detail
- target_compile_features specified unknown feature “cxx_std_14“ for target
- JVM tuning summary -xms -xmx -xmn -xss
猜你喜欢

2022 "strong country Cup" preliminary WP (with script and detailed process)

Restrict Su command and sudo mechanism to promote nmap and console command netstat

RecycleView实现item重叠水平滑动

A little consideration of strategic mode

Can communication test based on STM32: turn the globe

VSCode 如何开启多个终端?如何横向显示?

百度希壤首场元宇宙拍卖落槌,陈丹青六幅版画作品全部成交!

Baidu xirang's first yuan universe auction ended, and Chen Danqing's six printmaking works were all sold!

在C# WinForms应用程序中安装,配置和使用MetroFramework

JTAG debugging source level debugging of arm bare board debugging
随机推荐
How to troubleshoot the problem of too many inodes
HTX00001_ Keil51 bug encountered in serial port parsing
Example demonstration of math.random() random function
MySQL queries the table name under the current database
A scene application of 2D animation
Common API of window
Thread 类的基本用法
Mysql database backup and recovery
Introduction to the usage of explain and the meaning of result field in MySQL
Baidu SEM bidding avoidance
JSON、
2022深圳杯
Application of first-order complementary filtering to STM32 ADC acquisition
Jstat command summary [easy to understand]
Introduction to bridging mode and sharing mode
The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell
Memory memory operation function
VB variable types and control statements (basic)
Cointelegraph撰文:依托最大的DAO USDD成为最可靠的稳定币
JZ7 重建二叉树