Kangrui‘s Python Learning Diary 2020-07-18
文章目录
大小写变换
name = "ada lovelace"
print(name.title())
print(name.upper())
print(name.lower())输出结果为:
Ada Lovelace
ADA LOVELACE
ada lovelace连接字符串
nickname = "Kang"
full_name = name + " " + nickname
print(full_name)输出结果为:
ada lovelace Kang特殊符号
print("python")
print("\tpython") # 制表符
print("Language:\npython") # 换行符输出结果为:
python
python
Language:
python连接字符串
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)输出结果为:
python
python
python
python数据类型转换
age = 23
combine_1 = space_2 + str(age)
print(combine_1)输出结果为:python23
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!
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论