后浪云Python教程:python中camel函数的使用
1、camel接收字符串形式的变量名,并将其转换为驼峰形式。
2、这个函数考虑的是变量形式的字符串,单词之间有相关的分隔,而不是直接连续的单词。
比如somefunctionname。
实例
from re import sub def camel(s): s = sub(r"(_|-)+", " ", s).title().replace(" ", "") return s[0].lower() + s[1:] # EXAMPLES camel('some_database_field_name') # 'someDatabaseFieldName' camel('Some label that needs to be camelized') # 'someLabelThatNeedsToBeCamelized' camel('some-javascript-property') # 'someJavascriptProperty' camel('some-mixed_string with spaces_underscores-and-hyphens') # 'someMixedStringWithSpacesUnderscoresAndHyphens'
以上就是python中camel函数的使用,希望对大家有所帮助。更多Python学习指路:后浪云python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
版权声明:
作者:后浪云
链接:https://www.idc.net/help/176749/
文章版权归作者所有,未经允许请勿转载。
THE END