脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python中lower函数实现方法及用法讲解

python中lower函数实现方法及用法讲解

2021-08-17 00:54宋宋大人 Python

在本篇文章里小编给大家整理的是一篇关于python中lower函数实现方法及用法讲解内容,有需要的朋友们可以学习参考下。

之前小编介绍过python中将字符串小写字符转为大写的upper函数的使用方法(upper函数)。有将小写转为大写的需要,那也有将大写转为小写的情况。本文主要介绍在python中可以将字符串大写自摸转换为小写字母的lower函数。

1、lower()

转换字符串中所有大写字符为小写

2、语法

?
1
str.lower() -> str

3、返回值

返回将字符串中的所有大写字母转换为小写字母的字符串

4、使用实例

?
1
2
3
#!/usr/bin/python3
str = "ABCDEFG"
print( str.lower() )

输出

abcdefg

以上就是python中lower函数的介绍,如果需要将字符串中个的大写转为小写,可以使用lower函数哦

lower函数实例

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#实现lower
def my_lower(string):
  if not string:
    return None
  
  lst = list(string)
  for index,item in enumerate(lst):#同时列出数字和下标
    ascii_index = ord(item)
    if 65 <= ascii_index <= 90:
      s = chr(ascii_index+32)
      lst[index] = s
  return ''.join(lst)
 
if __name__ == '__main__':
  print(my_lower("2345ZRdV"))

到此这篇关于python中lower函数实现方法及用法讲解的文章就介绍到这了,更多相关如何实现python中lower函数内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.py.cn/jishu/jichu/22270.html

延伸 · 阅读

精彩推荐