+ 2

Polymorphism in Python ???

I know, this question must be very simple for you guys. How does polymorphism in Python is actually looks like in code? Give some examples, please? I've searched on Google, but can't find any clear topic there.

11th Dec 2021, 9:47 AM
Maksat Ramazanov
Maksat Ramazanov - avatar
5 odpowiedzi
+ 2
[SOLVED] Thank you for advise, Herr Rozwel . I also think so. Thanks all.
11th Dec 2021, 11:58 AM
Maksat Ramazanov
Maksat Ramazanov - avatar
+ 1
I am not sure is it allowed to post external links there, so i can only advise you to copy your title and paste it in a browser. There are plenty of sites explaining this with examples. I believe it will be better than my approach to explain it here.
11th Dec 2021, 11:34 AM
Herr Rozwel
Herr Rozwel - avatar
+ 1
Maksat Ramazanov # Hi! Here is a simple example that explain polymorphism in Python: def add(a, b): return a + b # ’+’ gives polymorph. behavior. # Add integers. print(f"{add(2, 5) = }") # 7 # Add strings. print(f"{add('abc', 'def') = }") # abcdef # Add lists. print(f"{add([3, 4], [7, 9]) = }") # [3, 4, 7, 9] https://code.sololearn.com/cBPpur2jKdmc/?ref=app
11th Dec 2021, 4:29 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Thank you. That's really helpful, Per Bratthammar . Now I understand it more clearly.
11th Dec 2021, 4:59 PM
Maksat Ramazanov
Maksat Ramazanov - avatar
+ 1
Herr Rozwel people post external links all the time. I don't think it's an issue.
12th Dec 2021, 12:03 AM
Simon Sauter
Simon Sauter - avatar