首页 > 编程语言 > 详细

A Pythonic Object

时间:2020-02-10 09:23:00      阅读:48      评论:0      收藏:0      [点我收藏+]

1. Object Representations

Every object-oriented language has at least one standard way of getting a string representation from any object. Python has two: repr() and str() . And the special methods __repr__ and __str__ support repr() and str().

There are two additional special methods to support alternative representations of objects: __bytes__ and __format__ . The __bytes__ is called by bytes() to get the object represented as a byte sequence . Regarding __format__ , both the built-in function format() and the str.format() method call it to get string displays of objects using special formatting codes.

# In Python3 , __repr__ , __str__ , and __format__ must always return Unicode strings (type str). Only __bytes__ is supposed to return a byte sequence (type bytes)

 

 

 

 

 

 

end...

A Pythonic Object

原文:https://www.cnblogs.com/neozheng/p/12289638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!