Python 下划线转驼峰

代码如下:

def snake_to_camel(snake_str):
    components = snake_str.split('_')
    # 首字母小写,其余字母大写
    return components[0] + ''.join(x.title() for x in components[1:])

# 示例
snake_string = "example_string"
camel_string = snake_to_camel(snake_string)
print(camel_string)  # 输出: exampleString