In Python, we have method reverse
within List
. It reverses the order of a list
.
Example:
[1, 2, 3].reverse() // [3, 2, 1]
But this method is not present in a string.
example (Python):
myString = "The String"
myString.reverse() // AttributeError: 'str' object has no attribute 'reverse'
1 - How would I revert this string to Python
?
Another issue is that in javascript , for example, we have Prototype
, where you can add a method to a language class native.
Example (Javascript):
String.prototype.hello = function() {
return this.toString() + " hello!";
}
"teste".hello() // "teste hello!"
2 - Is there a way to create a method directly in the String class of Python
?