๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_str.asp
Python str() Function
The str() function converts the specified value into a string. ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ builtins โ€บ stdtypes.html
Built-in Types โ€” Python 3.14.8 documentation
Return the next item from the iterator. If there are no further items, raise the StopIteration exception. This method corresponds to the tp_iternext slot of the type structure for Python objects in the Python/C API.
Discussions

In what cases do you use the str() function?
str() is used to generate a 'human readable string expression' for an object in python. Say for example , we have the following class in python: class Person: def __init__(self,name,age): self.name = name self.age = age print(Person('Anon',30)) This prints <__main__.Person object at 0x7f12b3fc7400> Which is a pointer to the memory address , not very helpful to comprehend. On the other hand , class Person: def __init__(self,name,age): self.name = name self.age = age def __str__(self): return f"Name:{name} Age:{age}" print(Person('Anon',30)) will print Name:Anon Age:30 which is more human readable ( kinda). The same thing happens with int - it has an inbuilt __str__ method which parses the input and converts it into a human readable string ( using ASCII/UTF-8 conversion or whatever). If you are still interested , I'd recommend going and reading up on __repr__ , which is similar to __str__ but is intended to be used via debugging rather than returning a string representation. Tbf , you can get around this using fstrings .... More on reddit.com
๐ŸŒ r/learnpython
8
8
July 16, 2021
What does __str__ method do?
Yeah, it's just so you can print it. If you try to print a variable that is not a string it won't know what to do, so when you make a __str__ method it's like saying "If I tell you to print this variable, this is how I want you to do that" More on reddit.com
๐ŸŒ r/learnpython
13
4
November 14, 2020
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ builtin-types โ€บ str
str | Pythonโ€™s Built-in Data Types โ€“ Real Python
In this example, strings are used to format and present user data in a readable format. ... Work with Python strings using a rich set of operators and functions: string literals, the str() function, and the methods you'll use most.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-str-function
Python str() function - GeeksforGeeks
July 15, 2025 - The str() function in Python is an in-built function that takes an object as input and returns its string representation. It can be used to convert various data types into strings, which can then be used for printing, concatenation, and formatting.
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python strings
Python Strings | Python Education | Google for Developers
Characters in a string can be accessed using the standard [ ] syntax, and like Java and C++, Python uses zero-based indexing, so if s is 'hello' s[1] is 'e'. If the index is out of bounds for the string, Python raises an error.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-string.html
Python Strings
Negative numbers also work within [ ] and slices: -1 is the last char in the string, and -2 is the next to last char, and so on. So for example with s = 'Python', s[-1] is 'n' and s[-2] is 'o'. This is convenient when you want to refer chars near the end of the string, and it works in slices too.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ str
Python str() (With Examples)
Online Python Online JavaScript Online SQL Online Java Online HTML Online C Online C++ Online C# Online PHP Online Swift Online Kotlin Online TypeScript Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The str() method returns the string representation of a given object.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ in what cases do you use the str() function?
r/learnpython on Reddit: In what cases do you use the str() function?
July 16, 2021 -

Title. I know you use it for integers, but in what context? Also, is it used for anything else?

Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_strings.asp
Python Strings
Like many other popular programming languages, strings in Python are arrays of unicode characters.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ dunder methods โ€บ __str__()
Python | Dunder Methods | __str__() | Codecademy
April 24, 2025 - In Python, objects can be represented as strings to make them more meaningful and easier to read. The __str__() method is one of Pythonโ€™s special methods, also known as dunder methods (double underscore methods).
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what does __str__ method do?
r/learnpython on Reddit: What does __str__ method do?
November 14, 2020 -

I'm still a beginner in python and my English is not really good, so I may have a little bit of understanding the explanation given in my course.

So I have this code:

class Apple:
    def __init__ (self,color,flavor):
        self.color=color
        self.flavor=flavor
        
    def __str__(self):
        return "This apple is {} and its flavor is {}".format(self.name,self.flavor)
        
jonagold=Apple("red","sweet")
print(jonagold)

The only purpose I see in using the __str__ method, I don't have to write the method in the print () line. If I changed the __str__ method with:

def say(self):
    return "This apple is {} and its flavor is {}".format(self.name,self.flavor)

I would just need to type

print(jonagold.say())

And I would get the same answer. What are the other purpose of using __str__? In what situation would I need to use the __str__?

Thank you :)

๐ŸŒ
Python-future
python-future.org โ€บ str_object.html
str โ€” Python-Future documentation
Here is an example that works identically on Python 2.x and 3.x: >>> from builtins import str >>> s = str(u'\udcff') >>> s.encode('utf-8', 'surrogateescape') b'\xff'
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-string-tutorial
Python String Tutorial | DataCamp
January 18, 2018 - You can handle textual data in Python using the str object. Strings are immutable sequences of unicode. Unicode is a system designed to represent all characters from languages. In unicode, each letter, character is represented as a 4-byte number.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ built-in โ€บ str()
Python str() - Convert to String
November 22, 2024 - The str() function in Python provides a simple yet powerful means of converting various data types into strings.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is python __str__?
What is Python __str__? | Scaler Topics
June 11, 2024 - In Python, class objects are represented as strings with the help of the python __str__ method. This method is also called as magic method or dunder method. The python __str__ method returns the string representation of the object. The same method is also called when the str() or print() function ...
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python-str-function.htm
Python str() Function
This function takes a value 'x' as a parameter that you want to convert into a string.