网站首页 > 基础教程 正文
比较简单的学习,什么也不说了,直接上代码:
#--------------------------------------------
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)
运行结果如下:
您好,世界!
-------------
Sun Guo Dong
-------------
SUN GUO DONG
-------------
sun guo dong
-------------
sun guo dong
-------------
hello,Sun Guo Dong!
-------------
python
-------------
python
-------------
python
-------------
www.gov.cn/
感觉还是比较好用的,当然还有好多函数,先写这些调试一下吧!
猜你喜欢
- 2024-11-01 关于Python字符串的那些事 python字符串常见操作
- 2024-11-01 Python文件读写 python文件读写操作方法
- 2024-11-01 Python如何去掉字符串中不需要的字符
- 2024-11-01 一文掌握Python 中的文件处理 python对文件处理
- 2024-11-01 Python对文件的操作及对异常的处理
- 2024-11-01 如何将python脚本打包成exe文件 py脚本转exe
- 2024-11-01 站长在线:Python中去除字符串中的空格和特殊字符的4个方法详解
- 2024-11-01 python中字符串类型 python字符串常用的五种方法
- 2024-11-01 Python中pandas.Series.str.strip()数据处理方法的理解
- 最近发表
- 标签列表
-
- jsp (69)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- pythonif (86)
- location.href (69)
- dockerexec (65)
- tail-f (79)
- queryselectorall (63)
- location.search (79)
- bootstrap教程 (74)
- 单例 (62)
- linuxgzip (68)
- 字符串连接 (73)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)