温馨提示×

Python函数如何返回字符串

九三
3118
2021-02-09 16:39:03
栏目: 编程语言

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!

0