2.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
20d
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
6mo
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
1y

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
2y

>>> 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

...read more
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
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter