首页 > 后端开发 > Python教程 > tuple and list 练习

tuple and list 练习

PHP中文网
发布: 2017-07-06 18:13:48
原创
1420 人浏览过

Tuple:

1.       __add__

<span style="color: #008080">1</span> a = (1,2,3,4,5,6,7,8,9<span style="color: #000000">,)
</span><span style="color: #008080">2</span> b = (10,11,22,33,44,55,66<span style="color: #000000">,),
</span><span style="color: #008080">3</span> c = (110,112,113,114<span style="color: #000000">,),
</span><span style="color: #008080">4</span> result = a.<span style="color: #800080">__add__</span><span style="color: #000000">(b)
</span><span style="color: #008080">5</span> <span style="color: #0000ff">print</span>(result)             <span style="color: #008000">#</span><span style="color: #008000">(1, 2, 3, 4, 5, 6, 7, 8, 9, (10, 11, 22, 33, 44, 55, 66))  add(b)里面只能加一个参数,否则会报错</span>
<span style="color: #008080">6</span> <span style="color: #0000ff">print</span>(a+b+c)              <span style="color: #008000">#</span><span style="color: #008000">(1, 2, 3, 4, 5, 6, 7, 8, 9, (10, 11, 22, 33, 44, 55, 66), (110, 112, 113, 114))</span>
登录后复制
<span style="color: #008080">1</span> a = (1,2,3,4,5,6,7,8,9<span style="color: #000000">,)
</span><span style="color: #008080">2</span> b = (10,11,22,33,44,55,66<span style="color: #000000">,)
</span><span style="color: #008080">3</span> c = (110,112,113,114<span style="color: #000000">,)
</span><span style="color: #008080">4</span> result = a.<span style="color: #800080">__add__</span><span style="color: #000000">(b)
</span><span style="color: #008080">5</span> <span style="color: #0000ff">print</span>(result)             <span style="color: #008000">#</span><span style="color: #008000">(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22, 33, 44, 55, 66)  有没有逗号的区别哈哈</span>
<span style="color: #008080">6</span> <span style="color: #0000ff">print</span>(a+b+c)              <span style="color: #008000">#</span><span style="color: #008000">(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22, 33, 44, 55, 66, 110, 112, 113, 114)</span>
登录后复制

 

以上是tuple and list 练习的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板