HHMathewChan
Posted on June 4, 2022
Question
- write a program to reverse a given string
str1 = "PYnative"
- Expected output
evitanYP
My attempt
str1 = "PYnative"
reversed_string = str1[::-1]
print(reversed_string)
Recommend solution
str1 = "PYnative"
print("Original String is:", str1)
str1 = ''.join(reversed(str1))
print("Reversed String is:", str1)
My reflection
I only know how to reversed a string using string slicing method, but do not know the reverse() and the join().
💖 💪 🙅 🚩
HHMathewChan
Posted on June 4, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.