call function in class python code example

Example 1: python call function in class

#------------------------------------
#CLASS
#------------------------------------
class Student:
  def __init__(self):
    self.name = None
    
  def set_name(self, word):
    self.name = word
    return self.get_name()
    
  def get_name(self):
    return self.name
  
#------------------------------------
# USAGE:
#------------------------------------

a = Student()
print(a.set_name("Hello"))

Example 2: python call function in the same class

# Add the argument ".self" before your function's name --> line 12

class ThisClass:
  	def __init__(self):
  		self.a_random_arg = a_random_arg
    
    def FirstDef(self):
   		[Here my function]
      
    def SecondDef(self):
    	if self.FirsDef:
          [following]