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__

def __str__(self):
        return self.name
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 make a stopwatch in pythoon 
Python :: Example of ceil method in python 
Python :: deleting a tuple in python 
Python :: reversing in python 
Python :: parse_dates 
Python :: python cat 
Python :: keras model 2 outputs 
Python :: get midnight of current day python 
Python :: create array with shape 0,2 
Python :: draw bipartite graph networkx 
Python :: remove dict last element 
Python :: np logical not 
Python :: seaborn stripplot range 
Python :: for i in array in range python 
Python :: length of series pandas 
Python :: django model functions 
Python :: dictionary input from user in python3 
Python :: extract specific key values from python dictionary 
Python :: extract directory python 
Python :: joining lists python 
Python :: pca in python 
Python :: alphabet 
Python :: deleting key from dictionary 
Python :: python find closest date 
Python :: discord python application bot 
Python :: how to count all files on linux 
Python :: pandas fillna multiple columns 
Python :: How to clone or copy a list in python 
Python :: python all() function 
Python :: simple python class 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =