Answers for "python class property"

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
1

class attributes in python

class MyClass:
  # Class attributes are defined outside of constructor
  class_attr = 0
  
  def __init__(self, inst):
    # Instance attributes are defined in the constructor
    self.instance_attr = inst
    
obj = MyClass(1)
print(obj.class_attr) # outputs 0
print(obj.instance_attr) # outputs 1
print(MyClass.class_attr) # outputs 0
print(MyClass.instance_attr) # raises AttributeError
Posted by: Guest on May-30-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
0

how to use a class in python

class awwab(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def speak(self):
        print("Hello, my name is",self.name,"and I am",self.age,"years old!")
        
awwabasad = awwab("Awwab Asad", 11)
print(awwabasad.speak())
Posted by: Guest on July-31-2021
0

Python Class Example

#Source: https://vegibit.com/python-class-examples/
class Vehicle:
    def __init__(self, brand, model, type):
        self.brand = brand
        self.model = model
        self.type = type
        self.gas_tank_size = 14
        self.fuel_level = 0

    def fuel_up(self):
        self.fuel_level = self.gas_tank_size
        print('Gas tank is now full.')

    def drive(self):
        print(f'The {self.model} is now driving.')

obj = Vehicle("Toyota", "Carola", "Car")
obj.drive()
Posted by: Guest on May-17-2021
0

python classmethod property

class classproperty(property):
    def __get__(self, cls, owner):
        return classmethod(self.fget).__get__(None, owner)()
Posted by: Guest on October-16-2021

Code answers related to "python class property"

Python Answers by Framework

Browse Popular Code Answers by Language