来一段代码,用来驼峰转下划线,用python写
时间: 2023-04-04 19:04:46 浏览: 97
以下是用 Python 编写的驼峰转下划线的代码:
```python
def camel_to_snake(camel_case):
snake_case = ''
for i, char in enumerate(camel_case):
if char.isupper() and i > 0:
snake_case += '_'
snake_case += char.lower()
return snake_case
```
使用方法:
```python
camel_case = 'camelCase'
snake_case = camel_to_snake(camel_case)
print(snake_case) # 输出 'camel_case'
```
希望能对您有所帮助!
阅读全文