课程: Advanced Python (2018)

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Class string values

Class string values

- [Instructor] Another fairly common operation in Python is converting different kinds of values into string representations. So consider, for example, what happens when you use the string formatting function. Each one of the parameters, passed to the format function, is converted into a string and then substituted into the output string at that particular place holder. Now, for some data types that's pretty straightforward, so just converting an integer number into a string. Python gives your custom class full control over how it wants to represent itself in string form, and there are essentially four main functions used to do this. The first, is the str function, this function is called on your class when the str, print, or string.format functions are used to convert the object to a string and, obviously, the return value has to be a string. This particular string is typically an informal representation of the object. In other words, its just a nicely formatted human readable…

内容