码迷,mamicode.com
首页 > 编程语言 > 详细

[py]a python tutor

时间:2020-02-22 11:59:58      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:else   namespace   its   方法   cas   callable   dea   delattr   spec   

python设计哲学

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!

python语言特性

用一些特殊标识来约定(自觉遵守,不要求强制)
    常量定义: 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里方法和类

// 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):

[py]a python tutor

标签:else   namespace   its   方法   cas   callable   dea   delattr   spec   

原文地址:https://www.cnblogs.com/iiiiiher/p/12344608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!