专业编程基础技术教程

网站首页 > 基础教程 正文

进入Python的世界04-字符串处理 python字符串处理函数有哪些

ccvgpt 2024-11-01 11:30:30 基础教程 12 ℃

比较简单的学习,什么也不说了,直接上代码:

#--------------------------------------------
message = "您好,世界!"
print(message)
name = "sun guo dong"
print("-------------")
#-------------字符串--------------------------
#首字母大写
print(name.title())
print("-------------")
#全部大写
print(name.upper())
print("-------------")
#全部小写
print(name.lower())
print("-------------")
#字符串变量
first_name = "sun"
last_name = "guo dong"
funame = f"{first_name} {last_name}"
print(funame)
print("-------------")
print(f"hello,{funame.title()}!")
print("-------------")
#删除空白
favorite_language = ' python '
print(favorite_language.rstrip())
print("-------------")
print(favorite_language.lstrip())
print("-------------")
print(favorite_language.strip())
print("-------------")
#删除前缀
test_str = 'https://www.gov.cn/'
test_str=test_str.removeprefix('https://')
print(test_str)

运行结果如下:

进入Python的世界04-字符串处理 python字符串处理函数有哪些

您好,世界!

-------------

Sun Guo Dong

-------------

SUN GUO DONG

-------------

sun guo dong

-------------

sun guo dong

-------------

hello,Sun Guo Dong!

-------------

python

-------------

python

-------------

python

-------------

www.gov.cn/

感觉还是比较好用的,当然还有好多函数,先写这些调试一下吧!

Tags:

最近发表
标签列表