Write a program to print a string in reverse without using built-in methods.

AnswerBot
1y
This program reverses a given string without using any built-in methods.
Iterate through the string from the last character to the first character.
Append each character to a new string to reverse the o...read more
Harshita Gupta
7mo
def reverse_string(input_string): # Initialize an empty string to hold the reversed string reversed_string = "" # Iterate through the input string in reverse order for i in range(len(input_string) - 1...read more
Priyadharshini
1y
works at
# Write Python code to reverse a string def reverse_string(string): ans = "" for letter in string: ans = letter + ans # Prepend each letter to reverse the string return ans result = reverse_string("ab...read more
Anonymous
2y
We can reverse a string using string slice operation
Str[::-1]
Atmuri Ganesh
2y
s=input("enter a string")
rev=""
for i in range(len(s)):
rev=s[i]+rev
print(rev)
Mark Macalua
2y
def reverse(s):
return s[::-1]
str = 'hello world'
print(reverse(str))
Yash Vijay
2y
def reverse_string(n):
for i in n:
reverse = n[::-1]
return reverse
n= "string"
prrint(reverse_string(n))
Yogesh Pandiya
3y
...read more
>>> Original_string = "this is a string"
>>> string=""
>>> for j in range(len(Original_string)):
j=j+1
a = (Original_string[-j])
string = string + a
>>>print(string )
Output: gnirts a si siht
OR
Anonymous
3y
first calculate the length of the input value and then start printing in reverse using negative index
Add answer anonymously...
Accenture Python Developer interview questions & answers
A Python Developer was asked 7mo agoQ. Define a lambda function and provide an example.
A Python Developer was asked 7mo agoQ. What are the differences between a list and a tuple?
A Python Developer was asked 7mo agoQ. What is a namespace and what are its types?
Popular interview questions of Python Developer
A Python Developer was asked 7mo agoQ1. Define a lambda function and provide an example.
A Python Developer was asked 7mo agoQ2. What are the differences between a list and a tuple?
A Python Developer was asked 7mo agoQ3. What is a namespace and what are its types?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

