python __str__repr__ 区别
__str__
__repr__
两个内置函数都是调试常用的函数, 对象直接调用时会调用 __repr__的内容, __str__需要print一下对象才可以
两个函数的内容有时会写成相同内容 __repr__ = __str__
>>> class Test(object):
... def __init__(self, value='hello world!'):
... self.data = value
...
...
>>> class TestRepr(Test):
... def __str__(self):
... return "TestRepr(%s)--str" %self.data
... def __repr__(self):
... return "TestRepr(%s)--repr" %self.data
...
>>> test = TestRepr()
>>> test
TestRepr(hello world!)--repr
>>> print test
TestRepr(hello world!)--str
python __str__repr__ 区别的更多相关文章
- C语言和python的区别
Python可以说是目前最火的语言之一了,人工智能的兴起让Python一夜之间变得家喻户晓,Python号称目前最最简单易学的语言,现在有不少高校开始将Python作为大一新生的入门语言.本萌新也刚开 ...
- Python学习---Java和Python的区别小记
Java和Python的区别小记 注意这里使用的是 and/or/not 非java中的&&,||,!Java中的true是小写 Python中函数就是对象,函数和我们之前的[1,2 ...
- 【python】ipython与python的区别
[python]ipython与python的区别 (2014-06-05 12:27:40) 转载▼ 分类: Python http://mba.shengwushibie.com/itbook ...
- Python - __name__=='__main__'是干啥的,以及python -m与python的区别
1. __name__=='__main__'是干啥的 先看例子,准备a.py和b.py放在同一个文件夹中 vi a.py # coding: utf-8 print("i am just ...
- python语法区别
python语法区别: 大小写敏感 (动态语言:python)变量不用声明 p.s: 静态语言(Java)必须声明变量 语句末尾可以不打分号 可以直接进行数学计算 复制.粘贴功能失效,粘贴到别的地方的 ...
- python 2 与python 3区别汇总
python 2 与python 3区别汇总 一.核心类差异1. Python3 对 Unicode 字符的原生支持.Python2 中使用 ASCII 码作为默认编码方式导致 string 有两种类 ...
- ipython与python的区别
http://mba.shengwushibie.com/itbook/BookChapter.asp?id=8745 http://www.cnblogs.com/yangze/archive/20 ...
- python中#!/usr/bin/python与#!/usr/bin/env python的区别
目的是在运行python脚本的时候告诉操作系统我们要用python解释器去运行py脚本 所以我们在第一句往往会写如下两句中的其中一句: #!/usr/bin/python 或 >#!/usr/b ...
- java的this static public protected private abstract interface 在python的对应,java python一些区别
1.因为工作的原因,最近使用了三个多月的java作为主力语言.很早之前在菜鸟教程也看过java文档两遍,但实践少,处于能看懂写出来不流畅的状态(对于java必须要略懂,不能能看到就头疼跳过,因为现在百 ...
随机推荐
- EasyUI combotree 设置节点折叠和叶子节点循环展开的BUG
树实体 public class Combotree { public string id { get; set; } public string text { get; set; } public ...
- 《SQL Server 2012 T-SQL基础》读书笔记 - 5.表表达式
Chapter 5 Table Expressions 一个表表达式(table expression)是一个命名的查询表达式,代表一个有效的关系表.SQL Server包括4种表表达式:派生表(de ...
- telnet测试端口是否打开?
如何测试远程服务器的某个端口是否打开? 例如: telnet 192.168.1.1 5000 返回: Trying 127.0.0.1...Connected to 127.0.0.1.Escape ...
- React-Native 之 GD (一)目录结构与第三方框架使用与主题框架搭建
1.APP效果图 2.工程环境配置 IOS: 将压缩包内的 Images.xcassets 文件夹直接替换掉我们iOS工程中的 Images.xcassets 文件夹. 这时候我们可以看到所有图片资源 ...
- 【洛谷P1036 选数】
这个题显然用到了深搜的内容 让我们跟着代码找思路 #include<bits/stdc++.h>//万能头 ],ans; inline bool prime(int n)//最简单的判定素 ...
- JS-预留字符和转义字符转换
字符实体(Entity) 转义字符(Escape Sequence)也称字符实体 (Character Entity). 定义转义字符串的主要原因是: <和>等符号已经用来表示 HTML ...
- Django路由小知识
from django.urls import path,re_path from app01 import views urlpatterns = [ re_path(r'^articles/200 ...
- template标签就相当于React中的fragment
template标签就相当于React中的fragment
- 锐捷网络自动连接python脚本
1 实现锐捷网络的连接,当断开后自动重连 import os import sys import time ip = 'www.baidu.com' print('开始ping百度') backinf ...
- sql中unique和distinct
在SQL语法里面,有unique和distinct两个关键字, unique是distinct的同义词,功能完全相同.distinct是标准语法,其他数据库 sql server,db2,oracle ...