Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

__str__ method python

class Person:
    def __init__(self, first_name, last_name, age):
        self.first_name = first_name
        self.last_name = last_name
        self.age = age

    def __str__(self):
        return f'Person({self.first_name},{self.last_name},{self.age})'
Code language: Python (python)
Comment

__str__python

The __str__ method in Python represents the class objects as a string – it can be used for classes. 
This method is called when print() or str() function is invoked on an object. This method must return the String object.
Comment

PREVIOUS NEXT
Code Example
Python :: how to reshape dataframe in python 
Python :: python timeit 
Python :: coloring text in python 
Python :: forgot django admin password 
Python :: add new row to dataframe pandas 
Python :: rgb color python 
Python :: how to add to the end of an array python 
Python :: python thread stop 
Python :: gráfico barras python 
Python :: python create a dictionary of integers 
Python :: hash table in python 
Python :: counting combinations python 
Python :: count occurrences of character in string python using dictionary 
Python :: How to store the input from the text box in python 
Python :: correlation for specific columns 
Python :: python count same number in list 
Python :: how to calculate the variance of all columns in python 
Python :: seaborn.distplot() 
Python :: python raise exception 
Python :: sphere volume formula 
Python :: split a string into an array of words in python 
Python :: use map in python to take input 
Python :: inplace pandas 
Python :: replace comma with dot in column pandas 
Python :: get the name of all files in a computer in python 
Python :: python if type dict 
Python :: numpy linspace of dates 
Python :: how to see if a number is prime in python 
Python :: virtual environments for python 
Python :: change key of dictionary python 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =