Python3基础 函数 无return、return 空或None 的效果相同
- Python : 3.7.3
- OS : Ubuntu 18.04.2 LTS
- IDE : pycharm-community-2019.1.3
- Conda : 4.7.5
- typesetting : Markdown
code
coder@ubuntu:~$ source activate py37
(py37) coder@ubuntu:~$ ipython
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: def fun_no_return():
...: pass
...:
In [2]: def fun_return_none():
...: return None
...:
In [3]: def fun_return_empty():
...: return
...:
In [4]: import dis
In [5]: dis.dis(fun_no_return)
2 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
In [6]: dis.dis(fun_return_empty)
2 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
In [7]: dis.dis(fun_return_none)
2 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
In [8]: exit
(py37) coder@ubuntu:~$ conda deactivate
coder@ubuntu:~$
source_code
def dis(x=None, *, file=None, depth=None):
"""Disassemble classes, methods, functions, and other compiled objects.
With no argument, disassemble the last traceback.
Compiled objects currently include generator objects, async generator
objects, and coroutine objects, all of which store their code object
in a special attribute.
"""
if x is None:
distb(file=file)
return
# Extract functions from methods.
if hasattr(x, '__func__'):
x = x.__func__
# Extract compiled code objects from...
if hasattr(x, '__code__'): # ...a function, or
x = x.__code__
elif hasattr(x, 'gi_code'): #...a generator object, or
x = x.gi_code
elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or
x = x.ag_code
elif hasattr(x, 'cr_code'): #...a coroutine.
x = x.cr_code
# Perform the disassembly.
if hasattr(x, '__dict__'): # Class or module
items = sorted(x.__dict__.items())
for name, x1 in items:
if isinstance(x1, _have_code):
print("Disassembly of %s:" % name, file=file)
try:
dis(x1, file=file, depth=depth)
except TypeError as msg:
print("Sorry:", msg, file=file)
print(file=file)
elif hasattr(x, 'co_code'): # Code object
_disassemble_recursive(x, file=file, depth=depth)
elif isinstance(x, (bytes, bytearray)): # Raw bytecode
_disassemble_bytes(x, file=file)
elif isinstance(x, str): # Source code
_disassemble_str(x, file=file, depth=depth)
else:
raise TypeError("don't know how to disassemble %s objects" %
type(x).__name__)
reference
resource
- [文档 - English] docs.python.org/3
- [文档 - 中文] docs.python.org/zh-cn/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 函数 无return、return 空或None 的效果相同的更多相关文章
- Python3基础 函数 无参数无返回值 调用会输出hello world的函数
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 函数 关键字参数 的示例
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- Python3基础 函数名.__doc__显示一个函数的单行与多行函数文档
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- Python3基础 定义无参数无返回值函数 调用会输出hello world的函数
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- Python3基础-函数实例学习
内置函数 绝对值函数 x = abs(100) y = abs(-20) print('x=100的绝对值为:{}'.format(x)) print('y=-20的绝对值为:{}'.format(y ...
- Python3基础 函数 递归 阶乘与斐波那契数列
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础——函数
ython 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可 ...
- Python3基础 函数 有参数有返回值 对传入的参数加1
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 函数 __name__ 得到引用所指向的真正名字
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
随机推荐
- Gtest:事件
前言 有时候在测试的时候,我们会在测试前做一些初始化活动,和测试后做一些清理工作,gtest提供了多种事件机制,非常方便我们在案例之前或之后做一些操作.总结一下gtest的事件一共有3种: 全局的,所 ...
- 21.centos7基础学习与积累-007-远程连接
从头开始积累centos7系统运用 大牛博客:https://blog.51cto.com/yangrong/p5 IP地址: 互联网上的计算机 都会有一个唯一的32位的地址,ip地址,我们访问服务器 ...
- 使用Cloudera Manager部署Kafka消息队列
使用Cloudera Manager部署Kafka消息队列 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.下载需要安装的Kafka版本 1>.查看Cloudera Dis ...
- Java数据库操作的一些注意
练习一:插入一个学生的四六级成绩: //课后练习 public class task3 { //添加一条数据 @Test public void testInsert() { int id=1; Sc ...
- 与你一起学习MS Project——高级篇:Project高级应用
我们再来看Project的一些高级应用. 一.设置任务依赖性的几种方法 首先是设置任务依赖性的几种方法,这里介绍三种方法. 方法一:选中两个需要建立依赖型的任务.选中用 ctrl 鼠标左键 的方式即可 ...
- Spring源码窥探之:扩展原理BeanFactoryPostProcessor
BeanPostPorcessor是在bean创建对象初始化前后进行拦截工作,而BeanFactoryPostProcessor是Bean工厂的后置处理器,在Bean定义加载完成之后,Bean实例初始 ...
- List.Sort
static void Main(string[] args) { List<double> valuesList = new List<double>(); valuesLi ...
- ztree异步加载---------补发周日内容
上周六老师要求和大三的进行JAVA知识交流,总体来说就是给大三学长做的东西打分,然后大三学长再教我们如果构建ztree.毕竟第一次接触ztree,所以有很多不了解,但通过周六日努力,还是做出来了.现在 ...
- H5中实现加载更多的逻辑及代码执行。
H5中加载更多的逻辑总结: 1.首先,需要三个底部的提示,分别是“加载中”.“--我是有底线的--”.“暂时没有记录”,当然,这三句话根据不同的项目,可以自定义.具体代码例子如下: <div c ...
- 洛谷P2877 [USACO07NOV]防晒霜Sunscreen
题目 此题有多种贪心方法. 首先简化题意: 有几个在数轴上的区间,和几个在数轴上确定的位置的点,问用这些数目的点,最多能满足多少个区间里有点. 注意:此题跟区间选点问题不一样,每个点只能满足一个区间, ...