大小寫變換python
name = "ada lovelace" print(name.title()) print(name.upper()) print(name.lower())
輸出結果爲:less
Ada Lovelace ADA LOVELACE ada lovelace
鏈接字符串ide
nickname = "Kang" full_name = name + " " + nickname print(full_name)
輸出結果爲:ui
ada lovelace Kang
特殊符號this
print("python") print("\tpython") # 製表符 print("Language:\npython") # 換行符
輸出結果爲:idea
python python Language: python
鏈接字符串spa
space_1 = 'python ' print(space_1) space_1 = space_1.rstrip() # 末尾的空格 print(space_1) space_2 = ' python ' print(space_2) space_2 = space_2.strip() # 兩端的空格 print(space_2)
輸出結果爲:code
python python python python
數據類型轉換ip
age = 23 combine_1 = space_2 + str(age) print(combine_1)
輸出結果爲:The Zen of Python, by Tim Peters
ci
Python之禪
import this
輸出結果爲:
The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!