Tuesday 14 August 2018

Pythonめも : tuple tuple tuple!

なんか、tupleという言葉に引っかかってしまって。
で、ググってみました。
Tupleとは:
複数のものからなっている組みの構成要素数を表している集合数詞である。

成る程。やっとわかった感じ。つまりは複数からなる文字や数のことをいうのですね。

よし、早速試してみよう。

s = [1,3,4,5,7,13,44,67]
new_s = s+[51, 15]
print(new_s)

結果:

[1, 3, 4, 5, 7, 13, 44, 67, 51, 15]

-------------

y = ["test ","is ","important"]
new_y = y+["that ","I"," think"]
print(new_y)

結果:

['test ', 'is ', 'important', 'that ', 'I', ' think']

-------------

y = ["test ","is ","important"]
new_y = y+["that ","I"," think"]
for i in new_y:
    print(i)

結果:
test 
is 
important
that 
I

 think

ああ、またforの使い方忘れちゃった。いけないわ。
--------------
tuple = (1,2,3)
n_tuple = tuple * 3
print(n_tuple)

結果:

(1, 2, 3, 1, 2, 3, 1, 2, 3)

↓ランキングに参加しています。是非、ポチッとお願いしますの。↓
にほんブログ村 IT技術ブログ IT技術メモへ
にほんブログ村

No comments:

Post a Comment