Asked 3 years ago
5 Aug 2021
Views 542
Evalyn

Evalyn posted

How do reverse string in Python , Java , PHP ?

What is reverse string ?
QuickIos

QuickIos
answered Aug 8 '21 00:00

Python :
Python have many way to reverse the string

i use while loop to do it so , concept is every string is made of array of character .

v='Hello World'
i=len(v)-1
while(i>=0):
	print(v[i],end="")
	i=i-1;
print()

it loop in revese by decreasing the length of the string :

it will print reverse string

dlroW olleH

ching

ching
answered Aug 19 '21 00:00

PHP :

we do get the length of the string and run reverse the for loop to get the reverse string.

strlen used to get string length

<?php
$d= "I m god"; 

for($i=strlen($d);$i>=0;$i--){
	echo $d[$i];
}
 
?>
Post Answer