python驼峰字符串转蛇形字符串
def camelToSnake(s
):
up_index
= []
for i
, c
in enumerate(s
):
if c
.isupper
():
up_index
.append
(i
)
ls
= s
.lower
()
list_ls
= list(ls
)
if up_index
:
addi
= 0
for g
in up_index
:
list_ls
.insert
(g
+ addi
, '_')
addi
+= 1
last_ls
= ''.join
(list_ls
)
return last_ls
s
='baseColor'
a
=camelToSnake
(s
)
print(a
)
转载请注明原文地址:https://tech.qufami.com/read-6831.html