[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

class human: def __init__(self,name,birthdate): self.name

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 12
Thread images: 2

File: Python.png (34KB, 502x270px) Image search: [Google]
Python.png
34KB, 502x270px
class human:
def __init__(self,name,birthdate):
self.name = name
self.birthdate = birthdate
def app(self):
return 4

class person(human):
def __init__(self,name,birthdate,age):
super().__init__(name,birthdate)
self.age = age
def app(self):
return super().app()




a = person("bob",1888,22)

print(a.app())




I need help understanding this code. why do i need to put a return before super().app()?

when i call the app method on the a instance shouldn't the app method of the supperclass be run?

when you remove return in the person class and print a.app() it returns None
>>
Install Gentoo

Do You Own Homework
>>
Never mind, i figured it out.

I was starting to think i wasn't a fucking genius.
>>
>>60892032
Human is inheriting human, so it is a subclass of the super class "human". When person calls its app function, it calls its super class' app method that it inherited, and returns the value that it gets from this method (4 in this case).
>>
python is such a garbage language for OOP, holy shit.
>>
>>60892032
Because you're returning the result of that function, it's the most awkward inheritance ever. You're not just running the function.

If this is private study, do yourself a favour and get into both java and c#, it's always one or the other and people don't realise they're the same paradigm and 90% the same syntax. Also, inheritance is neater.

>>60892241
Modern C# is getting close to C style pseudo code with capitalisation and semicolons and scope.

I'm actually not offended by Python handling scope with indentation, it removes the where to put semicolon arguments.
>>
File: 2352313.jpg (100KB, 658x439px) Image search: [Google]
2352313.jpg
100KB, 658x439px
>>60892032
>Python
>>
>>60893621
Python is great.
t. C programmer
>>
>>60892032
def app(self):
return super().app()

Why? Won't calling person.app() without that stupid definition invoke the parent class's definition anyways?
>>
>>60893779
Yup. Whoever wrote that is full on pajeet, holy fuck. You're learning from that OP?
>>> class human():
... def app(self):
... return 4
...
>>> class person(human):
... def __init__(self):
... self.age = "pajeet"
...
>>> a = person()
>>> print(a.app())
4
>>
>>60893681
>t. C programmer
Exactly, why would you be able to judge about language quality.
>>
>>60893681
>t. C programmer

Figures.
Thread posts: 12
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.