Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,519 members, 7,808,895 topics. Date: Thursday, 25 April 2024 at 06:52 PM

Programmers Help! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Programmers Help! (677 Views)

Please Web Programmers Help Me On This / Pls Programmers Help With Similarities Of Pseudocode & Algorithm / Programmers Help! My Final Project (2) (3) (4)

(1) (Reply) (Go Down)

Programmers Help! by cristofa: 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)

A Simple Question / Check It Out / Anti-virus

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.