【说站】python中camel函数的使用
Python 使用 函数 camel
2023-06-13 09:13:24 时间
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电脑。
相关文章
- Python入门系列(十一)一篇搞定python操作MySQL数据库
- python中dtype的使用规范_Python numpy.dtype() 使用实例
- python中列表(list)函数及使用
- 符合python命名规范的标识符是什么_Python标识符命名规范
- 【说站】python中fail函数如何使用
- 【说站】Python类属性如何使用
- 【说站】python copy模块中的函数使用
- 【说站】python多进程中多个参数函数的使用
- python pip卸载不了库,比如使用pyinstaller时greenlet报错但卸载不了
- python抛出异常写法_零基础学 Python(32):如何抛出和捕获异常?「建议收藏」
- python定义函数求和_Python定义函数实现累计求和操作
- 【测试开发】python系列教程:Python数据类型转换
- Python 使用浏览器自动化工具 Selenium 实现网页自动截图
- 使用 Python 拆分文本文件的最快方法是什么?
- python多进程编程-进程池的使用(二)
- python-Python与MySQL数据库-使用Python执行MySQL查询
- 自动化测试常用断言的使用方法(python)详解编程语言
- Python函数使用方法(高级用法)
- 使用交互式 shell 来增强你的 Python
- Python的函数嵌套的使用方法
- 使用python实现递归版汉诺塔示例(汉诺塔递归算法)