码迷,mamicode.com
首页 > 编程语言 > 详细

A Pythonic Object

时间:2020-02-10 10:04:11      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:uil   nbsp   ever   python   func   nic   color   any   display   

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

标签:uil   nbsp   ever   python   func   nic   color   any   display   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!