Chapter 02:变量和简单数据类型

2018-12-11  本文已影响0人  蜜糖_7474

title()以首字母大写的方式显示每个单词,即将每个单词的首字母都改为大写。

name = "ada lovelace.like him,and then"
print(name.title())

Ada Lovelace.Like Him,And Then

rstrip() 删除末尾空白 lstrip() 删除前端空白 strip() 删除前后空格

favorite_language = '   pyt hon  '
print(favorite_language.rstrip())
print(favorite_language.lstrip())
print(favorite_language.strip())

(反白看效果)

   pyt hon
pyt hon  
pyt hon

upper() 字符串全大小 lower() 字符串全小写

str = "HeLLo wORld"
print(str.upper())
print(str.lower())

HELLO WORLD
hello world

** 代表乘方

print(3 ** 3)

27

python存在浮点数误差

print(0.2+0.1 == 0.3)

False

与python2的小不同

print(3/2)

1.5

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!

上一篇 下一篇

猜你喜欢

热点阅读