Answers for "how to create class in python"

18

create and use python classes

class Mammal:
    def __init__(self, name):
        self.name = name

    def walk(self):
        print(self.name + " is going for a walk")


class Dog(Mammal):
    def bark(self):
        print("bark!")


class Cat(Mammal):
    def meow(self):
        print("meow!")


dog1 = Dog("Spot")
dog1.walk()
dog1.bark()
cat1 = Cat("Juniper")
cat1.walk()
cat1.meow()
Posted by: Guest on December-30-2019
21

how to make a class in python

class Person:
  def __init__(self, _name, _age):
    self.name = _name
    self.age = _age
   
  def sayHi(self):
    print('Hello, my name is ' + self.name + ' and I am ' + self.age + ' years old!')
    
p1 = Person('Bob', 25)
p1.sayHi() # Prints: Hello, my name is Bob and I am 25 years old!
Posted by: Guest on November-17-2019
5

python define class

class uneclasse():
  def __init__(self):
    pass
  def something(self):
    pass
xx = uneclasse()
xx.something()
Posted by: Guest on February-04-2020
19

python class

class Person:#set name of class to call it 
  def __init__(self, name, age):#func set ver
    self.name = name#set name
    self.age = age#set age
   

    def myfunc(self):#func inside of class 
      print("Hello my name is " + self.name)# code that the func dose

p1 = Person("barry", 50)# setting a ver fo rthe class 
p1.myfunc() #call the func and whitch ver you want it to be with
Posted by: Guest on June-12-2020
12

class python

class MyClass(object):
  def __init__(self, x):
    self.x = x
Posted by: Guest on May-12-2020
-1

how to create class in python

x.counter = 1
while x.counter < 10:
    x.counter = x.counter * 2
print(x.counter)
del x.counter
Posted by: Guest on June-18-2021

Code answers related to "how to create class in python"

Python Answers by Framework

Browse Popular Code Answers by Language