标签:else namespace its 方法 cas callable dea delattr spec
Pythonic就是以Python的方式写出简洁优美的代码
In [1]: 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!
用一些特殊标识来约定(自觉遵守,不要求强制)
常量定义: WEEKDAY = 8
类中权限保护: 方法名前加 __
//变量
支持定义后不使用
支持重复声明定义
a = 10
a = 'm'
变量名和要避讳py关键字
In [1]: import keyword # python3.6.6
In [2]: keyword.kwlist
Out[2]:
['False',
'None',
'True',
'and',
'as',
'assert',
'break',
'class',
'continue',
'def',
'del',
'elif',
'else',
'except',
'finally',
'for',
'from',
'global',
'if',
'import',
'in',
'is',
'lambda',
'nonlocal',
'not',
'or',
'pass',
'raise',
'return',
'try',
'while',
'with',
'yield']
In [3]: len(keyword.kwlist)
Out[3]: 33
python3.8新增了async await关键字. 总共35个.
//函数
不支持重载
支持不定参数
支持返回多值
// buildins.py里的函数(体现py面向过程)
abs
all
any
ascii
bin
callable
chr
compile
copyright
credits
delattr
dir # 函数不带参数时,返回当前范围内的(变量/类型/对象)列表; 带参数(变量/类型/对象)时,返回参数的属性、方法列表。
divmod
eval
exec
exit
format
getattr
globals
hasattr
hash
help
hex
id # cpython中取的是内存地址
input
isinstance
issubclass
iter
len
license
locals
max
min
next
oct
open
ord
pow
print
quit
repr
round
setattr
sorted
sum
vars
__build_class__
__import__
// buildins.py里常见类(体现py面向对象)
class object:
class type(object)
type(object_or_name, bases, dict)
type(object) -> the object's type
type(name, bases, dict) -> a new type
class int(object)
class bool(object)
class str(object)
class tuple(object)
class list(object)
class dict(object)
class enumerate(object):
标签:else namespace its 方法 cas callable dea delattr spec
原文地址:https://www.cnblogs.com/iiiiiher/p/12344608.html