What is the meaning of “int(a[::-1])” in Python?

0 votes
I cannot understand this. I have seen this in people's code. But cannot figure out what it does. This is in Python.
str(int(a[::-1]))
Aug 27, 2018 in Python by bug_seeker
• 15,510 points
227 views

1 answer to this question.

0 votes

Assumming a is a string. The Slice notation in python has the syntax -

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

So, when you do a[::-1] , it starts from the end, towards the first, taking each element. So it reverses a. This is applicable for lists/tuples as well.

Example -

>>> a = '1232' >>> a[::-1] '2321'

Then you convert it to int and then back to string (Though not sure why you do that) , that just gives you back the string.

answered Aug 27, 2018 by Priyaj
• 57,700 points

Related Questions In Python

0 votes
1 answer

What is the Python logic to count the number of capital letters in a file?

Hi, You can use this piece of code, ...READ MORE

answered Jun 26 in Python by Roshni
• 4,690 points
79 views
0 votes
1 answer

.What is the meaning of "while True :" while doing in a loop.

The body of the loop will continue ...READ MORE

answered Oct 7 in Python by Gitika
• 41,720 points
18 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
2,448 views
0 votes
1 answer

What is the use of raw_input function in Python?

raw_input fuction is no longer available in ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
267 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,465 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,094 views
0 votes
1 answer

What is the use of “assert” keyword in Python?

You can try the following in a ...READ MORE

answered Oct 15, 2018 in Python by Priyaj
• 57,700 points
203 views
0 votes
1 answer

What is the fucntion of mkdir -p in Python

mkdir -p gives you an error if the ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 57,700 points
231 views