if the number is positive, I reverse it as a string and return it as an integer
if the number is negative, I do the same method but without looking at the first char (-), then I return it as a negative integer (which is exactly like your method)
The advantage is that you can "convert" both positive and negative numbers !
May I suggest for Python:
A little bit more concise:
-
), then I return it as a negative integer (which is exactly like your method) The advantage is that you can "convert" both positive and negative numbers !examples:
Also, if you want to go deeper and converting both integer and float, you could use something like this !
Which allows: