How do I retrieve the "this" value in python like the "prototype" method in JavaScript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I retrieve the "this" value in python like the "prototype" method in JavaScript?

11th Oct 2020, 11:53 PM
Stephen John Miszczyk
Stephen John Miszczyk - avatar
5 Answers
+ 1
Your question is unclear. prototype is not a method and it isn't used to retrieve the "this" value. Well. In python there's no "this" but something called "self" is used instead: https://www.sololearn.com/learn/Python/2467/ Tutorial on self: https://code.sololearn.com/ce664AekBveN/?ref=app
12th Oct 2020, 3:30 AM
Kevin ★
+ 1
Thanks for clarifying. It's not possible to modify python classes that way. The closest approach I can think is extending the built-in class but that's far from Javascript prototypes: https://code.sololearn.com/c3Q55kMTR4C5/?ref=app You can't force a language to behave as other because their features and design are different.
12th Oct 2020, 6:15 AM
Kevin ★
+ 1
I'm interested in the results of your research. I don't understand what you mean with "if join can do it maybe there's a way" tho, but keep me posted.
12th Oct 2020, 6:25 PM
Kevin ★
0
For example in JavaScript I would write String.prototype.reverse=function(){for(i=this.length;abc.length<=this.length-1;i--){abc+=this[i-1]};return(abc)}; and use it as "reverse this string".reverse()
12th Oct 2020, 5:51 AM
Stephen John Miszczyk
Stephen John Miszczyk - avatar
0
Thanks man I'll do some more research i figured if join can do it maybe there's a way.
12th Oct 2020, 8:53 AM
Stephen John Miszczyk
Stephen John Miszczyk - avatar