Python3 笔记:upper()、isupper()、lower()、islower()、swapcase()

1、upper() 方法将字符串中的小写字母转为大写字母。

语法:str.upper()

2、isupper() 方法检测字符串中所有的字母是否都为大写。

语法:str.isupper()

如果字符串中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是大写,则返回 True,否则返回 False。

3、lower() 方法转换字符串中所有大写字符为小写。

语法:str.lower()

4、islower() 方法检测字符串是否由小写字母组成。

语法:str.islower()

5、swapcase() 方法用于对字符串的大小写字母进行转换,即将大写字母转换为小写字母,小写字母会转换为大写字母。

语法:str.swapcase()

str1 = 'Hello World'
str2 = str1.upper()
str3 = str1.lower()
str4 = str1.swapcase()
print(str2)					# 运行结果:HELLO WORLD
print(str3)					# 运行结果:hello world
print(str4)					# 运行结果:hELLO wORLD
print(str1.isupper())		# 运行结果:False
print(str2.isupper())		# 运行结果:True
print(str1.islower())		# 运行结果:False
print(str3.islower())		# 运行结果:True

相关推荐

  1. Python笔记3

    2024-06-15 01:04:02       22 阅读
  2. Python3 笔记:位运算符

    2024-06-15 01:04:02       34 阅读
  3. Python3 笔记:分支结构

    2024-06-15 01:04:02       37 阅读
  4. Python3 笔记:顺序结构

    2024-06-15 01:04:02       29 阅读
  5. Python3 笔记:range() 函数

    2024-06-15 01:04:02       29 阅读
  6. Python3 笔记Python的函数

    2024-06-15 01:04:02       33 阅读
  7. 【《流畅的python3.2-3.3节学习笔记

    2024-06-15 01:04:02       29 阅读
  8. python笔记3)基本数据类型简介

    2024-06-15 01:04:02       48 阅读
  9. Python3 笔记:负数的二进制

    2024-06-15 01:04:02       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-15 01:04:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-15 01:04:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-15 01:04:02       82 阅读
  4. Python语言-面向对象

    2024-06-15 01:04:02       91 阅读

热门阅读

  1. git创建新分支

    2024-06-15 01:04:02       31 阅读
  2. Python 3和Python 2之间主要区别

    2024-06-15 01:04:02       28 阅读