方法1: python
a = str(input()) print(a[::-1])
解:
import numpy as np a=np.random.rand(5) print(a) [ 0.64061262 0.8451399 0.965673 0.89256687 0.48518743] print(a[-1]) ###取最后一个元素 [0.48518743] print(a[:-1]) ### 除了最后一个取全部 [ 0.64061262 0.8451399 0.965673 0.89256687] print(a[::-1]) ### 取从后向前(相反)的元素 [ 0.48518743 0.89256687 0.965673 0.8451399 0.64061262] print(a[2::-1]) ### 取从下标为2的元素翻转读取 [ 0.965673 0.8451399 0.64061262]
方法2: python
a = input() L = list(a) L.reverse() for letter in L: print(letter,end = '')
方法3: C
int main() { long int num; char s[100]={}; scanf("%d",&num); int i = 0; while (num) { s[i++] = (num % 10)+ '0'; num /= 10; } i = 0; while (s[i] != '\0') { printf("%c",s[i]); i++; } return 0; }
方法4:C
#include<stdio.h> #include<string.h> int main() { char str[10000]; gets(str); int len=strlen(str); for(int i=len-1;i>=0;i--) { printf("%c",str[i]); } }