Heim  >  Artikel  >  Backend-Entwicklung  >  Tupel- und Listenübung

Tupel- und Listenübung

PHP中文网
PHP中文网Original
2017-07-06 18:13:481361Durchsuche

Tupel:

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>

 

Das obige ist der detaillierte Inhalt vonTupel- und Listenübung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn