导语:
本文主要介绍了关于python中camel函数的使用的相关知识,包括python中get函数,以及python中concat函数这些编程知识,希望对大家有参考作用。
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'
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ python 使用 as 来指定别名10/26
- ♥ 如何在python中输入多行08/20
- ♥ python中如何消除正负数的符号来计算均值10/10
- ♥ python中如何判断值是否为008/27
- ♥ python中浅拷贝和深拷贝模块的使用01/08
- ♥ Python选择排序算法的性能分析10/11
内容反馈