编写一个函数将字符串转换为驼峰表示法
时间: 2023-05-25 17:03:28 浏览: 208
```python
def to_camel_case(text):
# 将字符串按照'-'或者'_'进行分割
# 并将每一个单词的首字母大写
words = [word.capitalize() for word in text.replace('-', '_').split('_')]
# 将首字母小写,并将所有单词拼接成一个字符串
return words[0].lower() + ''.join(words[1:])
```
示例:
```python
print(to_camel_case("hello-world")) # helloWorld
print(to_camel_case("foo_bar_baz")) # fooBarBaz
print(to_camel_case("fooBarBaz")) # fooBarBaz
```
阅读全文