品易云推流 关闭
文章详情页
文章 > Python基础教程 > python中camel函数的使用

python中camel函数的使用

Python camel

头像

小妮浅浅

2021-10-22 10:01:454904浏览 · 0收藏 · 0评论

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电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图