Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

Kindly help me in understanding the below code:

str(int(a[::-1]))

1 Answer

0 votes
by (107k points)

Let's take a string variable named as str1. The syntax that you are referring to is known as Slice notation in Python-

list[<start>:<stop>:<step>]

So, when you write:

[::-1]

It will begin from the end towards the first extracting each element. So it will reverse a. This is applicable for lists/tuples as well.

Say for instance:

>>> a = '1234'

>>> a[::-1]

'4321'

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...