Write a program to reverse a string without using in-built functions in python
Here's the Python code to reverse a string without using in-built functions:
# take input string from user
string = input("Enter a string: ")
# initialize an empty string to store reversed string
reversed_string = ""
# loop through the string in reverse order and append each character to the reversed string
for i in range(len(string)-1, -1, -1):
reversed_string += string[i]
# print the reversed string
print("Reversed string:", reversed_string)
In this program, we first take a string as input from the user. Then, we initialize an empty string to store the reversed string. We loop through the input string in reverse order and append each character to the reversed string using the += operator. Finally, we print the reversed string using the print() function.
原文地址: https://www.cveoy.top/t/topic/FQ7 著作权归作者所有。请勿转载和采集!