python中实现字符串翻转的方法
具体代码如下所示:
#字符串反转 def reverse (s): rt = '' for i in range(len(s)-1,-1,-1): rt += s[i] return rt def reverse2 (s): li = list(s) li.reverse() rt = "".join(li) return rt def reverse3 (s): return s[::-1] def reverse4 (s): return "".join(reversed(s)) from functools import reduce def reverse5 (s): return reduce(lambda x,y:y+x,s)
前两种是传统方法,后两种比较新颖
总结
相关推荐
HMHYY 2020-07-28
ELEMENTS爱乐小超 2020-07-04
amazingbo 2020-06-28
alicelmx 2020-06-16
minkee 2020-06-09
逍遥友 2020-06-02
嗡汤圆 2020-05-10
whbing 2020-05-05
zhuxianfeng 2020-05-02
assastor 2020-05-01
JessePinkmen 2020-05-01
hongxiangping 2020-04-30
theta = np.zeros #theta = array,构造全为零的行向量。grad[0,j] = np.sum/len #∑term / m. return value > threshol
Kwong 2020-04-26
88483063 2020-04-23
xirongxudlut 2020-04-19