![](https://s.togetter.com/static/web/img/placeholder.gif)
ノンプロ研初心者向けプログラミング講座第9期【Python コース】 第3回
![](https://s.togetter.com/static/web/img/placeholder.gif)
リストとタプルの大きな違い! タプルは要素の再代入が不能! GASで言うと、letとconstの違いみたいな感じだな #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 21:54:45![](https://s.togetter.com/static/web/img/placeholder.gif)
ほうほうほうほう #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/WeVDEFkuXo
2022-08-14 21:56:30![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
タプルもリストもマイナスインデックスで、最後の要素から順番に取り出せる #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 21:57:12![](https://s.togetter.com/static/web/img/placeholder.gif)
すでに要素が入ったタプルのインデックスに再代入すると、エラーが発生する #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 21:57:45![](https://s.togetter.com/static/web/img/placeholder.gif)
パックは、普通にタプルを、変数に代入してまとめること アンパックは、逆にタプルを、個別の変数にそれぞれ代入すること GASの分割代入のイメージかな #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/ENb64v8Ogn
2022-08-14 21:59:09![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
ふむふむ? #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/p9xHN96aEA
2022-08-14 22:01:05![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
x,yにアンパックしてるのに、 再度タプルになっているのかな??? あれ? #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:02:04![](https://s.togetter.com/static/web/img/placeholder.gif)
あ、なるほど! セルの最終行に、x,yって記述してる部分で、再度パックしているので、タプルリテラルで出力されるのか! それぞれの変数は、単に数値が代入されてるのが確認できますね。 #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/2feupa9uDF
2022-08-14 22:03:38![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
ということは、()無しでも、カンマ区切りのデータは、自動的にタプル化されるってこと?ん・・・? #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:04:19![](https://s.togetter.com/static/web/img/placeholder.gif)
うおー、しょーゆーこと?! #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/rIsJEMaadz
2022-08-14 22:04:46![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
さらっと、写経に変更を加えるこはた先生! そして、タプルは要素への再代入は不可能だけど、タプルを代入した変数には、再代入が可能なのですね・・・ #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:06:27![](https://s.togetter.com/static/web/img/placeholder.gif)
タプルの()は省略可能。 ただし、可読性の観点から、()の省略はすべきではない。ネットなどでは、()を省略したリテラルが散見されるそうです #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:07:22![](https://s.togetter.com/static/web/img/placeholder.gif)
アンパックされた変数自体は、ただの変数なので、上書き可能です。なるほど!!! #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:07:50![](https://s.togetter.com/static/web/img/placeholder.gif)
タプルでも、リストと同様に、[start,stop,step]でのスライスリテラルが使用可能! #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:08:21![](https://s.togetter.com/static/web/img/placeholder.gif)
タプルでは、要素が一つだけでも、カンマをつける必要がある!数値などでは、単純数値に変換されてしまうので。なるほどなるほど! #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:09:11![](https://s.togetter.com/static/web/img/placeholder.gif)
ということは、タプルは要素の変更は不可でも、要素の追加はできるってことですね? #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:10:21![](https://s.togetter.com/static/web/img/placeholder.gif)
ん? [:]のスライスリテラルって、つまりstart=0で、stop=3になってるかと思ったけど・・・ #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/OpxpnhYIsM
2022-08-14 22:13:20![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
ちょっとまった、分からないっす! numbers = (10, 30) numbers + (20,) この時点で、numbersは(10, 30, 20)ですよね? numbers[1:]は、stop省略なので、(30,20)ではないのですか? #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:16:26![](https://s.togetter.com/static/web/img/placeholder.gif)
スライスを適用すると、現在のタプルではなく、初期定義の状態にタプル対してのスライスになるってことなの? #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:17:15![](https://s.togetter.com/static/web/img/placeholder.gif)
タプル要素の存在確認は、リストと一緒で in not in が使える #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:18:03![](https://s.togetter.com/static/web/img/placeholder.gif)
次の写経の前に、さっきのが気になって、実験しました。 写経の1セル目2行目、「+=」が正解じゃないかな? #ノンプロ研 #Python講座 #タイムマシン受講 pic.twitter.com/HRXpTLSGJz
2022-08-14 22:20:17![](https://s.togetter.com/static/web/img/placeholder.gif)
![](https://s.togetter.com/static/web/img/placeholder.gif)
numbers + (20,) だと、 (10, 30, 20)ってタプルが生成されるので、そのタプルが出力はされるけど、どの変数にも格納されていないので、numbers自体は、(10, 30)のままになっていると思います。 #ノンプロ研 #Python講座 #タイムマシン受講
2022-08-14 22:21:48