使⽤re.sub转换字符串⼤⼩写import re
def pythonReSubDemo(inputStr):
"""
demo Pyton re.sub
"""
# inputStr = "recordInvalidDate"
def to_lower(matched):
s = up(0).lower()
t = f'_{s}'
return t
replaced_str = re.sub(r"([A-Z])", to_lower, inputStr)
"""
# 转换成字典
s_input = inputStr.strip()
s_replaced = replaced_str.strip()
dic = {
s_input: s_replaced
}
print(dic)
"""
print('replaced_str', replaced_str)    # record_invalid_date  ⼤写字母转成下划线 + ⼩写字母
if name == "main":
s1 = """
'economicType',
'companyHouseType',
'propertyType',
'propertyOwner',
'propertyDate',
'grossArea',
'systemSupplier',字符串函数中将大写转换为小写
'parkLocationClass',
'workerNum',
'parkCharger',
'mobilePhone',
'telPhone',
"""
s2 = s1.split(',')
for i in s2:
pythonReSubDemo(i)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。