Answers for "simple class example in python"

2

class in python

class LuckyLemur():
  	def __init__(self, description):
		self.description = description
	
    def reveal_description(self):
    	print(f'Lucky Lemur is {self.description}')

lucky_lemur = LuckyLemur('Pro')
lucky_lemur.reveal_description()
Posted by: Guest on June-02-2021
4

python class

class Dog(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def speak(self):
        print("Hi I'm ", self.name, 'and I am', self.age, 'Years Old')

JUB0T = Dog('JUB0T', 55)
Friend = Dog('Doge', 10)
JUB0T.speak()
Friend.speak()
Posted by: Guest on November-20-2020
1

what is a class in python

Classes are blueprint used to construct objects
Posted by: Guest on September-07-2021
1

classes in python

# Python classes

class Person():
  # Class object attributes (attributes that not needed to be mentioned when creating new class of person)
  alive = True
  
  def __init__(self, name, age):
    # In the __init__ method you can make attributes that will be mentioned when creating new class of person
    self.name = name
    self.age = age
    
  def speak(self):
    # In every method in class there will be self, and then other things (name, age, etc.)
    print(f'Hello, my name is {self.name} and my age is {self.age}') # f'' is type of strings that let you use variable within the string

person_one = Person('Sam', 23) # Sam is the name attribute, and 23 is the age attribute
person_one.speak() # Prints Hello, my name is Sam and my age is 23

==================================================================
# Output:

>>> 'Hello, my name is Sam and my age is 23'
Posted by: Guest on January-09-2021

Code answers related to "simple class example in python"

Python Answers by Framework

Browse Popular Code Answers by Language