+ 2

How can I reverse a string in py or js?

16th Apr 2021, 1:25 PM
Hisham Abdelgadir Mohamed
Hisham Abdelgadir Mohamed - avatar
8 Réponses
+ 2
# python str="Koanti" print(str[::-1]) // js let str = "Koanti"; console.log([...str].reverse().join(""));
16th Apr 2021, 1:53 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 3
Qasem your js code would be thrown a TypeError ??
16th Apr 2021, 1:55 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 1
In python str="Nitin" print(str[::-1])
16th Apr 2021, 1:35 PM
Atul [Inactive]
+ 1
Thanks Basel.Al_hajeri?.MBH() for objection👍
16th Apr 2021, 2:02 PM
Qasem
+ 1
In python Either use stringname.reverse() Or use String name[::-1]
16th Apr 2021, 2:25 PM
Akshay Panwar
Akshay Panwar - avatar
+ 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
16th Apr 2021, 3:03 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
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.
16th Apr 2021, 1:35 PM
Qasem
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))
16th Apr 2021, 1:49 PM
Amir
Amir - avatar