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 :: rename folder python 
Python :: semaphore in python 
Python :: python editor online 
Python :: flask app.route 
Python :: package python 
Python :: anaconda install python 
Python :: python wsgi 
Python :: python fme logger 
Python :: python permission denied 
Python :: cross entropy 
Python :: pythpn data tyoe 
Python :: how to read mysql table in python 
Python :: cannot unpack non-iterable int object when using python dicitonary 
Python :: Fill in the empty function so that it returns the sum of all the divisors of a number, without including it. A divisor is a number that divides into another without a remainder. 
Python :: add dataframe column to set 
Python :: Fun & learn with python turtle 
Python :: pygame draw square 
Python :: copy multiple files from one folder to another folder 
Python :: python 3.3 release date 
Python :: how to set background color for a button in tkinter 
Python :: tkinter while button not pressed 
Python :: python pattern 
Python :: count substring in string python 
Python :: python sort list case insensitive 
Python :: non blocking socket python 
Python :: how to add two strings in python 
Python :: how to access dictionary inside an array python 
Python :: how to make a operating system in python 
Python :: how to bubble sort a 2d array in python 
Python :: usage code grepper 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =