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文本统计功能之西游记用字统计操作

Python面试常见问题有哪些

运行Python脚本的方法是什么

Python如何识别图片中的文字

Python中定义类的关键字是什么

Python中的while什么意思

Python如何生成随机数字

Python中继承有什么用法?Python继承的用法详解

Python编程中notimplementederror的使用方法_Python

如何在Python中调用c函数

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




打赏

取消

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

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

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

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

评论

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