Kangrui‘s Python Learning Dairy 2020-07-18

大小写变换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 Petersci

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!
相关文章
相关标签/搜索