博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python字符串转换为小写字母– str.lower()
阅读量:2530 次
发布时间:2019-05-11

本文共 1382 字,大约阅读时间需要 4 分钟。

We can convert a string to lowercase in Python using str.lower() function. In this short tutorial, we will learn how to convert to lowercase.

我们可以使用str.lower()函数将字符串转换为小写。 在这个简短的教程中,我们将学习如何将转换为小写。

Python字符串转换为小写 (Python String to Lowercase)

Let’s look at a simple example of converting a string to lowercase and print it.

让我们看一个将字符串转换为小写并打印的简单示例。

s = '987abcDEF%$'print('Lowercase String =', s.lower())print('Original String =', s)

Output:

输出:

Lowercase String = 987abcdef%$Original String = 987abcDEF%$

Notice that when we call lower() on a string object, the original string remains unchanged. This function creates another string with lowercase characters and returns it. Special characters and numbers are unchanged because they don’t have uppercase and lowercase versions.

注意,当我们在字符串对象上调用lower()时,原始字符串保持不变。 此函数创建另一个带有小写字符的字符串并返回它。 特殊字符和数字不变,因为它们没有大写和小写版本。

带有用户输入的Python字符串lower() (Python String lower() with user input)

Let’s have a look at another example where we will get the user input and convert it to lowercase string and print it.

让我们看另一个示例,在该示例中,我们将获取用户输入并将其转换为小写字符串并进行打印。

s = input('Please Provide Input String\n')print('Input String in Lowercase =', s.upper())print('Original String =', s)

Output:

输出:

Please Provide Input StringJava is Nice!!Input String in Lowercase = java is nice!!Original String = Java is Nice!!
. 检出完整的python脚本和更多Python示例。

Reference:

参考:

翻译自:

转载地址:http://hamzd.baihongyu.com/

你可能感兴趣的文章
POJ 3728 The merchant(LCA+DP)
查看>>
移动Web开发规范
查看>>
Singly linked list algorithm implemented by Java
查看>>
金币阵列问题
查看>>
bzoj4318OSU &tyvj1952 Easy
查看>>
jmeter的JVM参数设置
查看>>
POJ1789 Truck History【最小生成树】【终于AC了】
查看>>
python基础09_文件操作
查看>>
mvn install selenium依赖包
查看>>
关于SQL的相关笔记【长期更新,只发一帖】
查看>>
linux awk命令详解
查看>>
android:id="@+id/button1" 与 android:id="@id/button1" 区别 @string
查看>>
根文件系统
查看>>
webpack主要内容
查看>>
关于defaultvalue在IE67的bug
查看>>
PHP 的 文件引入
查看>>
WinDbg抓取dmp文件
查看>>
Watchdog机制概述
查看>>
JS 过滤HTML标签,取得纯文本
查看>>
Springboot整合日志时候出现的问题
查看>>