₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,010 members, 8,419,916 topics. Date: Thursday, 04 June 2026 at 07:21 AM

Toggle theme

Programmers Help! - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingProgrammers Help! (802 Views)

1 Reply (Go Down)

Programmers Help! by cristofa(op): 11:18pm On Jun 23, 2015
Hello pyton programmers in the house. I recently began learning python and i came across a concept that i have failed to grasp:

class. method = method
or better still:
class Dog(object):
def __init__(self, name, breed, sex, age):
self.name = name
self.breed = breed
self.sex = sex
self.age = age
def bark(self):
return "Woof!"

Dog.bark = bark

Why do i have to this "Dog.bark = bark" what does it signify.

Thnks for your help
Re: Programmers Help! by omoelu1(m): 9:51am On Jun 24, 2015
cristofa:
Hello pyton programmers in the house. I recently began learning python and i came across a concept that i have failed to grasp:

class. method = method
or better still:
class Dog(object):
def __init__(self, name, breed, sex, age):
self.name = name
self.breed = breed
self.sex = sex
self.age = age
def bark(self):
return "Woof!"

Dog.bark = bark

Why do i have to this "Dog.bark = bark" what does it signify.

Thnks for your help
I want to believe Dog.bark = "bark" is what you meant to write.
if it is, then it means you are setting(declaring) a class variable #bark# which will have a value of "bark".
so anytime you reference Dog.bark, you will get the value "bark".
Re: Programmers Help! by bomsy1(m): 4:37pm On Jun 24, 2015
Just to fully clarify
'Class.method() = method' would give a syntax error, as you can't assign to a function call
As omoelu rightfully pointed, the bark in 'Dog.bark' is a class variable not a method.
Re: Programmers Help! by seunthomas: 4:43pm On Jun 24, 2015
@omoelu1 Is absolutely correct. Dog.bark = "bark" is a class variable created at runtime. One of the powerful features of python.
Re: Programmers Help! by lordZOUGA(m): 6:03pm On Jun 24, 2015
seunthomas:
@omoelu1 Is absolutely correct. Dog.bark = "bark" is a class variable created at runtime. One of the powerful features of python.
This doesn't feel powerful at all. Just another way for a developer to shoot himself in the leg.
Re: Programmers Help! by seunthomas: 8:01pm On Jun 24, 2015
lordZOUGA:
This doesn't feel powerful at all. Just another way for a developer to shoot himself in the leg.
Well, its very powerful because it allows for flexibility. Most newer scripting languages implemented this after python. And if am right some of the more powerful languages tried too but because of specification wahala they had to halt it. Note java and the other powerful languages are governed by boards that need to approve features into what we regard as the standardized form of the language.
1 Reply

Please Web Programmers Help Me On ThisPls Programmers Help With Similarities Of Pseudocode & AlgorithmProgrammers Help! My Final Project234

How To Build A Daily Deals Website In A Small Investment Of $149?Computer EducationEboooks- Holla Me