Answers for "how to create class object in python"

22

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
4

python class

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age
  def myfunc(self):
    print("Hello my name is " + self.name +".")

p1 = Person("Victor", 24)
p1.myfunc()
Posted by: Guest on April-30-2021
1

class python

class Employee(Object)
	def __init__(self, name, age, salary):
    	self.name = name
      	self.age = age
        self.salary = salary
        
        
  
  	def __str__(self)
    return f"Employee {name} nhes age {age} nand make {salary}"
Posted by: Guest on July-20-2021
7

what is a class in python

A class is a block of code that holds various functions. Because they
are located inside a class they are named methods but mean the samne
thing. In addition variables that are stored inside a class are named 
attributes. The point of a class is to call the class later allowing you 
to access as many functions or (methods) as you would like with the same
class name. These methods are grouped together under one class name due
to them working in association with eachother in some way.
Posted by: Guest on June-29-2020
1

class methods in python

@classmethod
def func(cls, args...)
Posted by: Guest on November-14-2020
0

how to create an object in python

class ClassName:
    self.attribute_1 = variable_1 #Set attributes for all object instances
    self.attrubute_2 = variable_2
    
    def __init__(self, attribute_3, attribute_4): #Set attributes at object creation
        self.attribute_3 = attribute_3            
        self.attribute_4 = attribute_4

    def method(self): #All methods should include self
		print("This is a method example.") #Define methods just like functions 


object = Object(4, "string") #Set attribute_3 and attribute_4
object.method() #Methods are called like this.
Posted by: Guest on August-09-2020

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

Python Answers by Framework

Browse Popular Code Answers by Language