python3 print end语句中的 end=''是什么意思呢

虾米音乐网() - 高品质音乐 发现 分享
Loading...
您所查看的歌曲不存在或已经删除
关注虾米:一个针对 Python 语句执行顺序的练习 - 简书
<div class="fixed-btn note-fixed-download" data-toggle="popover" data-placement="left" data-html="true" data-trigger="hover" data-content=''>
写了23257字,被4人关注,获得了8个喜欢
一个针对 Python 语句执行顺序的练习
摘自 Fluent Python
evalsupport.py
print('&[100]& evalsupport module start')
def deco_alpha(cls):
print('&[200]& deco_alpha')
def inner_1(self):
print('&[300]& deco_alpha:inner_1')
cls.method_y = inner_1
return cls
class MetaAleph(type):
print('&[400]& MetaAleph body')
def __init__(cls, name, bases, dic):
print('&[500]& MetaAleph.__init__')
def inner_2(self):
print('&[600]& MetaAleph.__init__:inner_2')
cls.method_z = inner_2
print('&[700]& evalsupport module end')
evaltime.py
from evalsupport import deco_alpha
print('&[1]& evaltime module start')
class ClassOne():
print('&[2]& ClassOne body')
def __init__(self):
print('&[3]& ClassOne.__init__')
def __del__(self):
print('&[4]& ClassOne.__del__')
def method_x(self):
print('&[5]& ClassOne.method_x')
class ClassTwo(object):
print('&[6]& ClassTwo body')
@deco_alpha
class ClassThree():
print('&[7]& ClassThree body')
def method_y(self):
print('&[8]& ClassThree.method_y')
class ClassFour(ClassThree):
print('&[9]& ClassFour body')
if __name__ == '__main__':
print('&[11]& ClassOne tests', 30 * '.')
one = ClassOne()
one.method_x()
print('&[12]& ClassThree tests', 30 * '.')
three = ClassThree()
three.method_y()
print('&[13]& ClassFour tests', 30 * '.')
four = ClassFour()
four.method_y()
print('&[14]& evaltime module end')
evaltime_meta.py
from evalsupport import deco_alpha
from evalsupport import MetaAleph
print('&[1]& evaltime_meta module start')
@deco_alpha
class ClassThree():
print('&[2]& ClassThree body')
def method_y(self):
print('&[3]& ClassThree.method_y')
class ClassFour(ClassThree):
print('&[4]& ClassFour body')
def method_y(self):
print('&[5]& ClassFour.method_y')
class ClassFive(metaclass=MetaAleph):
print('&[6]& ClassFive body')
def __init__(self):
print('&[7]& ClassFive.__init__')
def method_z(self):
print('&[8]& ClassFive.method_y')
class ClassSix(ClassFive):
print('&[9]& ClassSix body')
def method_z(self):
print('&[10]& ClassSix.method_y')
if __name__ == '__main__':
print('&[11]& ClassThree tests', 30 * '.')
three = ClassThree()
three.method_y()
print('&[12]& ClassFour tests', 30 * '.')
four = ClassFour()
four.method_y()
print('&[13]& ClassFive tests', 30 * '.')
five = ClassFive()
five.method_z()
print('&[14]& ClassSix tests', 30 * '.')
six = ClassSix()
six.method_z()
print('&[15]& evaltime_meta module end')
&&& import evaltime
&[100]& evalsupport module start
&[400]& MetaAleph body
# 说明类的 body 在导入时就执行
&[700]& evalsupport module end
&[1]& evaltime module start
&[2]& ClassOne body
&[6]& ClassTwo body
# 类的 body 中有其他类, 也会被执行
&[7]& ClassThree body # 先执行类的body, 然后将类作为类装饰器的参数
&[200]& deco_alpha
&[9]& ClassFour body
# 类继承并不会继承类装饰器
&[14]& evaltime module end
python evaltime.py
&[100]& evalsupport module start
&[400]& MetaAleph body
&[700]& evalsupport module end
&[1]& evaltime module start
&[2]& ClassOne body
&[6]& ClassTwo body
&[7]& ClassThree body
&[200]& deco_alpha
&[9]& ClassFour body
&[11]& ClassOne tests ..............................
&[3]& ClassOne.__init__
&[5]& ClassOne.method_x
&[12]& ClassThree tests ..............................
&[300]& deco_alpha:inner_1
# 装饰器修改了类属性
&[13]& ClassFour tests ..............................
&[300]& deco_alpha:inner_1
# ClassFour 继承的是经由装饰器修改后的ClassThree
&[14]& evaltime module end
&[4]& ClassOne.__del__
# 退出时垃圾回收
&&& import evaltime_meta
&[100]& evalsupport module start
&[400]& MetaAleph body
&[700]& evalsupport module end
&[1]& evaltime_meta module start
&[2]& ClassThree body
&[200]& deco_alpha
&[4]& ClassFour body
&[6]& ClassFive body
&[500]& MetaAleph.__init__ # 先 ClassFour 定义, 然后交给其元类对他加工
&[9]& ClassSix body
&[500]& MetaAleph.__init__ # 先 ClassFour 定义, 然后交给其元类对他加工, 由于继承自 ClassFive, 其元类同上(注意区分基类与元类)
&[15]& evaltime_meta module end
python3 evaltime_meta.py
&[100]& evalsupport module start
&[400]& MetaAleph body
&[700]& evalsupport module end
&[1]& evaltime_meta module start
&[2]& ClassThree body
&[200]& deco_alpha
&[4]& ClassFour body
&[6]& ClassFive body
&[500]& MetaAleph.__init__
&[9]& ClassSix body
&[500]& MetaAleph.__init__
&[11]& ClassThree tests ..............................
&[300]& deco_alpha:inner_1
&[12]& ClassFour tests ..............................
&[5]& ClassFour.method_y
&[13]& ClassFive tests ..............................
&[7]& ClassFive.__init__
&[600]& MetaAleph.__init__:inner_2
&[14]& ClassSix tests ..............................
&[7]& ClassFive.__init__
&[600]& MetaAleph.__init__:inner_2
&[15]& evaltime_meta module end
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:Python 3中print(fields[::2])语句是什么意思_python吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:117,572贴子:
Python 3中print(fields[::2])语句是什么意思收藏
fields=[&#39;asdf&#39;, &#39; &#39;, &#39;fjdk&#39;, &#39;;&#39;, &#39;afed&#39;, &#39;,&#39;, &#39;fjek&#39;, &#39;,&#39;, &#39;asdf&#39;, &#39;,&#39;, &#39;foo&#39;]print(fields[::2])运行结果是[&#39;asdf&#39;, &#39;fjdk&#39;, &#39;afed&#39;, &#39;fjek&#39;, &#39;asdf&#39;, &#39;foo&#39;]谢谢各位大神了
python,「亚马逊」中国网购专业平台,上千万种商品任您选!30天免费退换!
步长啊,书上不是有写吗
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或python安装完成后,输入IDLE报错** IDLE can&#039;t import Tkinter - Python - 学有网,您的在线问题检索平台
python安装完成后,输入IDLE报错** IDLE can&#039;t import Tkinter
08:50:34&&来源:慕课网
  python安装完成后输入python,可以出现编辑窗口
但是针对idle,会报错如下:
IDLE can't import Tkinter.
Your Python may not be configured for Tk.
下面给出解决方案,首先安装tcl-devel和tk-devel,
[ Desktop]# yum install tk-devel
然后把python版本重新编译和安装即可

我要回帖

更多关于 python end用法 的文章

 

随机推荐