关于python:Kangrui‘s-Python-Learning-Dairy-20200718

63次阅读

共计 1309 个字符,预计需要花费 4 分钟才能阅读完成。

大小写变换

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)

输入后果为:
The Zen of Python, by Tim Peters

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!

正文完
 0