Answers for "python define a class"

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
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
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
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
0

class python example

# If questions ask SK3#3160 he can help you i think
def ok(index):
    print(index) > Hi!
ok("Hi!")
class Lib:
    def ok(self,Token):
        print(Token) > Hello World!
Library = Lib()
Library.ok("Hello World!")
Posted by: Guest on January-08-2021

Code answers related to "python define a class"

Python Answers by Framework

Browse Popular Code Answers by Language