Welcome to Intellipaat Community. Get your technical queries answered by top developers!
How can I reverse a str object in Python?
The fastest approach to do this is using s[::-1] , You can also try ''.join(reversed(s)) it's comparatively more readable but three times slower. Ex.
>>> 'q string'[::-1]'gnirts q'
>>> ''.join(reversed('q string'))'gnirts q'
>>> ''.join(reversed('q string'))
Hope this helps. Cheers.....!!
Python gives us a very easy way to reverse our string:-
We can reverse our string by using Extended Slice method:-
This slicing method works by doing [begin: end: step] leaving begin and end off and specifying a step of -1, it reverses a string.
string= "hello world"string[::-1]
string= "hello world"
Certification in Digital Marketing |
Certification in Big Data Analytics |
Certification in Cloud & Devops |
Certification in Full Stack Web Development
Big Data and Data Science Master’s Course |
Data Science Architect Master’s Program |
Cloud and DevOps Architect Master’s Course |
Artificial Intelligence Engineer Master’s Course |
Microsoft Azure Certification Master’s Training
Data Science Course Online |
Big Data Hadoop Certification Training |
Machine Learning Course Online |
Artificial Intelligence Course and Training |
Salesforce Certification Training: Administrator and App Builder |
Tableau Training and Certification Course |
Python Data Science Course & Training |
Ethical Hacking Course |
Business Analyst Course |
Courses in Cyber Security
© COPYRIGHT 2011-2021 INTELLIPAAT.COM. ALL RIGHTS RESERVED.