Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

print class python

class yourClass:
    def __str__(self):
        return "value"  #replace value with what you want to print
Comment

how to print class attributes in python

an = Animal()
attrs = vars(an)
# {'kids': 0, 'name': 'Dog', 'color': 'Spotted', 'age': 10, 'legs': 2, 'smell': 'Alot'}
# now dump this in some way or another
print(', '.join("%s: %s" % item for item in attrs.items()))
Comment

Print object attributes in python

# listing out all attributes of an object in Python
# create a class
class Student:
    def __init__(self, name, id, age):
        self.name = name
        self.id = id
        self.age = age

    def info(self):
        return f"Student name: {self.name} and id: {self.id} "

    # class variable
    var = 1


# creating object
s1 = Student("Mradula", 1, 20)
s2 = Student("Joel", 2, 15)
print(s1.info())
print(s1.__dir__())
Comment

Print object attributes in python

# listing out all attributes of an object in Python
# create a class
class Student:
    def __init__(self, name, id, age):
        self.name = name
        self.id = id
        self.age = age

    def info(self):
        return f"Student name: {self.name} and id: {self.id} "

    # class variable
    var = 1


# creating object
s1 = Student("Mradula", 1, 20)
s2 = Student("Joel", 2, 15)
print(s1.info())
print(s1.__dir__())
Comment

PREVIOUS NEXT
Code Example
Python :: create virtualenv python3 
Python :: input function python 
Python :: how to add createsuper user in django 
Python :: sortedcontainers sorteddict import 
Python :: django rest framework function based views 
Python :: pandas apply 
Python :: basic flask app python 
Python :: Change Python interpreter in pycharm 
Python :: python map() 
Python :: max deviation in pandas 
Python :: change month name in python 
Python :: matplotlib legend get handles 
Python :: global variables python 
Python :: python singleton 
Python :: generate random list and find max in list python 
Python :: os.startfile 
Python :: appending to a list python 
Python :: python dataframe save 
Python :: python plus 
Python :: lists to dictionary python 
Python :: flask get uploaded file size 
Python :: how to add list numbers in python 
Python :: install ansible with pip 
Python :: r char to numeric dataframe all columns 
Python :: map to list python 
Python :: python min value index from an array 
Python :: mean python 
Python :: django login required 
Python :: Python program to find N largest elements from a list 
Python :: python sort an array 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =