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

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

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

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

Python字符串转换为大写 (Python String to Uppercase)

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

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

s = 'abcDEF%$'print('Uppercase String =', s.upper())print('Original String =', s)

Output:

输出:

Uppercase String = ABCDEF%$Original String = abcDEF%$

Notice that when we call upper() on a string object, the original string remains unchanged. This function creates another string with uppercase characters and returns it.

注意,当我们在字符串对象上调用upper()时,原始字符串保持不变。 此函数使用大写字符创建另一个字符串并返回它。

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

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

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

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

Output:

输出:

Please Provide Input StringJournalDev is Awesome!!Input String in Uppercase = JOURNALDEV IS AWESOME!!Original String = JournalDev is Awesome!!
. 检出完整的python脚本和更多Python示例。

Reference:

参考:

翻译自:

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

你可能感兴趣的文章
并发编程(十):AQS
查看>>
条件注释判断浏览器版本<!--[if lt IE 9]>
查看>>
Comparison among several SGD derivation
查看>>
ModelAndView同时向页面传递多个参数
查看>>
samba 配置参数详解
查看>>
shell 正则表达式
查看>>
expect 交互 之双引号较长变量
查看>>
Altium designer18设置原理图尺寸
查看>>
公司人数和气质的限制关系
查看>>
数据集成工具Teiid Designer的环境搭建
查看>>
Coap协议学习笔记-第一篇
查看>>
listview反弹实现详解
查看>>
Java高级架构师(一)第24节:加入ehcache,把工程加入到Git
查看>>
this用法(ryf)
查看>>
第一天博客园
查看>>
MP4文件格式的解析,以及MP4文件的分割算法
查看>>
FAT32与NTFS区别
查看>>
安卓开发环境搭建
查看>>
.NET日志工具 log4net
查看>>
线段树整理
查看>>