+ 2
How can I reverse a string in py or js?
8 Answers
+ 2
# python
str="Koanti"
print(str[::-1])
// js
let str = "Koanti";
console.log([...str].reverse().join(""));
+ 3
Qasem your js code would be thrown a TypeError ??
+ 1
In python
str="Nitin"
print(str[::-1])
+ 1
Thanks Basel.Al_hajeri?.MBH() for objectionđ
+ 1
In python
Either use
stringname.reverse()
Or use
String name[::-1]
+ 1
In C++
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a[100];
cin.getline(a,100);
int j=strlen(a)-1;
for(;printf("%c",a[j]),j>=0;j--);
return 0;
}
https://code.sololearn.com/c0HBIs3FX9ho/?ref=app
https://code.sololearn.com/cO57p45oQ8gK/?ref=app
https://code.sololearn.com/cp27hgTf9l0T/?ref=app
0
str = "abc"
python:
print(str[::-1])
js:
console.log(str.split("").reverse().join(""))
note that none of them won't change the original string because it's an immutable data type.
0
x='hello'
x=x[::-1]
print (x)
a='hello'
new=''
for i in a:
new=i+new
print(new)
b='hello'
b=list(b)
b.reverse()
print(''.join(b))
d='hello'
new=[]
n=len(d)-1
while n>-1:
new.append(d[n])
n-=1
print(''.join(new))