最近开始重新回过头来巩固一下python的基础知识,并在此做一些记录以便未来更好的回顾
使用title()方法可以将字符串中每个单词的首字母大写
1 name = "hello world" 2 print(name.title())
运行得到结果:
Hello World
1 name = "hello world" 2 print(name.upper())
运行得到结果:
HELLO WORLD
1 name = "HELLO WORLD" 2 print(name.lower())
运行得到结果:
hello world
1 first = "hello" 2 last = "world" 3 add = first + " " + last 4 print(add)
运行后得到结果:
hello world
1 print("\tpython")
运行得到结果:
#输出结果前有一个空格 python
1 print("languages:\nPython\nJava")
运行得到结果:
languages:
Python
Java
1 name = "python " 2 print(name.rstrip())
运行得到结果:
python
1 name = " python" 2 print(name.lstrip())
运行得到结果:
python
1 name = " python " 2 print(name.strip())
运行得到结果:
python
原文:https://www.cnblogs.com/lw-whatever/p/11631884.html