扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Python函数如何返回字符串

扬州沐宇科技
2021-02-09 16:39:03
python, 字符串

Python函数如何返回字符串

使用Python函数返回字符串的方法

1.lower()函数返回字符串

a = "Hello, World!"

print(a.lower())

输出结果为:

Hello, World!

2.使用upper()返回字符串

a = "Hello, World!"

print(a.upper())

输出结果为:

HELLO, WORLD!

3.使用replace()函数返回字符串

txt = "hello world!"

x = txt.replace("hello", "hi")

print(x)

输出结果为:

hi world!

扫码添加客服微信