tuple and list 练习


本文摘自php中文网,作者PHP中文网,侵删。

Tuple:

1.       __add__

1

2

3

4

5

6

<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>

1

2

3

4

5

6

<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 练习的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python中set不常用吗

“if __name__ == __main__:”有什么作用

Python解析socket数据流异常bytes的问题(详细)

Python编程怎么学

Python中subprocess类与常量的详细介绍

Python如何安装cvxopt

Python如何读取txt文件

有关Python的md5加密用法详解

linux怎么运行Python脚本?

Python里range什么意思

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...