【人工智能概述】python妙用 __str__()

【人工智能概述】python妙用 str()

文章目录


一.python内置函数__str__()

  • 通过自定义__str__()函数可以打印对象中相关的内容。
python 复制代码
class Person(object):
    def __init__(self, name = 'tom', age = 10):
        self.name = name
        self.age = age
        self.parent = None
    
    def __str__(self):
        return "Your name is: " + self.name
    
tom = Person()
print(tom)
 
# 唔,果然输出了我们自定义的内容
# >>> Your name is: tom
相关推荐
程序员老陆13 小时前
Qt::WidgetAttribute 常用属性详解
开发语言·qt
XLYcmy13 小时前
pdf论文处理:CSV输出模式
数据库·python·pycharm·pdf·论文·csv·dify
苏灿烤鱼13 小时前
14MB 模型,凭什么跟 270M 对打?
javascript·python·agent
特立独行的猫a15 小时前
Windows安装Rust环境 Clang替代GCC MinGW环境LLVM工具链(详细教程)
开发语言·windows·rust·mingw·环境搭建·llvm
m0_7202450121 小时前
1543.统计好三元组(简单)
开发语言·算法
小田学Python1 天前
100行Python代码,搭一个能干活的AI Agent
python·langchain·大模型·ai agent
叠层归一研究院1 天前
AGI 系统(八):符号范畴嵌入函子 — SymCat ↪ C_M107 严格化
c语言·开发语言·人工智能·算法·transformer·agi
明朝百晓生1 天前
Deep RL learning[2026/8]
开发语言·javascript·人工智能
Csvn1 天前
🐍 Day3 : Python 容器精讲 — list、dict、set、tuple 底层实现与高级操作
后端·python
weixin-a153003083161 天前
python-装饰器
开发语言·python