From the course: Advanced Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Class string values

Class string values - Python Tutorial

From the course: Advanced Python

Start my 1-month free trial

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…

Contents