camelcase_在Python中将字符串转换为camelCase
生活随笔
收集整理的這篇文章主要介紹了
camelcase_在Python中将字符串转换为camelCase
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
camelcase
Here, we are implementing a python program to convert a given string to camelCase.
在這里,我們正在實現一個python程序,將給定的字符串轉換為camelCase。
Example of camelCase:
camelCase的示例:
String: "Hello world"camelCase string: "helloWorld"Program:
程序:
# importing the module from re import sub# function to convert string to camelCase def camelCase(string):string = sub(r"(_|-)+", " ", string).title().replace(" ", "")return string[0].lower() + string[1:]# main code s1 = "Hello world" s2 = "Hello,world" s3 = "Hello_world" s4 = "hello_world.txt_includehelp-WEBSITE"print("s1: ", s1) print("camelCase(s1): ", camelCase(s1)) print()print("s2: ", s2) print("camelCase(s2): ", camelCase(s2)) print()print("s3: ", s3) print("camelCase(s3): ", camelCase(s3)) print()print("s4: ", s4) print("camelCase(s4): ", camelCase(s4)) print()Output
輸出量
s1: Hello world camelCase(s1): helloWorlds2: Hello,world camelCase(s2): hello,Worlds3: Hello_world camelCase(s3): helloWorlds4: hello_world.txt_includehelp-WEBSITE camelCase(s4): helloWorld.TxtIncludehelpWebsite翻譯自: https://www.includehelp.com/python/convert-a-string-to-camelcase.aspx
camelcase
總結
以上是生活随笔為你收集整理的camelcase_在Python中将字符串转换为camelCase的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: da---tlc5615._CD-DA的
- 下一篇: php分布式的锁,laravel分布式并