---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-b81b7df0c6f9> in <module>
      1 ''' appendメソッドの引数に同時に複数の要素を渡すことはできません。 '''
----> 2 list1.append(5, 6)
TypeError: append() takes exactly one argument (2 given)
''' もし要素のみを追加したい場合はextendメソッドを使います。 ''' list_a = [ 1 , 2 , 3 , 4 , 5 ] list_b = [ 'a' , 'b' , 'c' , 'd' , 'e' ] list_a . extend ( list_b ) print ( list_a )
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-03c883abbd72> in <module>
      1 tuple = (1, 2, 3, 4, 5)
----> 2 tuple.append(6)
AttributeError: 'tuple' object has no attribute 'append'
''' タプルに要素を追加するのはできないので新しいタプルを作る必要があります。'''
tuple = (1, 2, 3)
new_tuple = tuple + (4, 5)
print(new_tuple)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-29ae48f45c7a> in <module>
      1 str = 'これは文字列'
----> 2 str.append('です。')
AttributeError: 'str' object has no attribute 'append'
str_a = 'これは文字列' str_b = 'です。' str_c = str_a + str_b # 元の文字列を連結した別の文字列オブジェクトを作ります。 print(str_c) # formatメソッド str_d = '{}{}' # 元の文字列を連結した別の文字列オブジェクトを作ります。 print(str_d.format(str_a, str_b)) # fプリフィクス str_e = f'{str_a}{str_b}' # 元の文字列を連結した別の文字列オブジェクトを作ります。 print(str_e)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-50fafea6280d> in <module>
      1 ''' 辞書にもappendメソッドは使えません '''
      2 dict = {'a':1, 'b':2, 'c':3}
----> 3 dict.append('d')
AttributeError: 'dict' object has no attribute 'append'
# updateメソッドを使う。 another_dict = {'f':600, 'g':700} dict.update(another_dict) print(dict)
{'a': 100, 'b': 200, 'c': 300, 'd': 400}
{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 500}
{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 500, 'f': 600, 'g': 700}
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-6256c329d289> in <module>
      1 ''' 集合にもappendメソッドは使えません。 '''
      2 set = {1, 2, 3}
----> 3 set.append(4)
AttributeError: 'set' object has no attribute 'append'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-dc17991f387f> in <module>
      2 import numpy as np
      3 array = np.array([1, 2, 3])
----> 4 array.append(4)
AttributeError: 'numpy.ndarray' object has no attribute 'append'
''' numpyのarray(配列)に要素を追加する方法 '''
import numpy as np
array1 = np.array([0, 1, 2])
print(array1)
#  append関数を使う。
array2 = np.append(array1, 3)
print(array2)
#  insert関数を使う。
array3 = np.insert(array1, 3, 3)  #引数は配列、挿入する位置、挿入する値の順番
print(array3)
		

Python初心者におすすめのプログラミングスクール

「未経験からでもPythonを学べるプログラミングスクールを探しているけど、色々ありすぎてわからない」なら、次の3つのプログラミングスクールから選んでおけば間違いはありません。

Aidemy Premium:全くの初心者ができるだけ効率よく短期間で実務的に活躍できるAI人材になることを目的とした講座。キャリアカウンセリングや転職エージェントの紹介などの転職支援も充実しており、受講者の転職成功率が高い。

AIジョブカレPythonの基本をおさえた人が、実際に機械学習やディープラーニングを活用できるようになるための講座。転職補償型があるなどキャリア支援の内容が非常に手厚く、講師の質も最高クラス。コスパ最高。Python初心者用の対策講座もある。

データミックスプログラミング経験者のビジネスマンが、更なるキャリアアップのためにデータの処理方法を学んでデータサイエンティストになるための講座。転職だけでなく起業やフリーランスとして独立する人も多い。Python初心者用の対策講座もある。

特に、あなたが以下のような目標を持っているなら、この中から選んでおけば間違いはないでしょう。

・未経験からPythonエンジニアとして就職・転職したい
・AIエンジニアやデータサイエンティストとしてキャリアアップしたい
・起業やフリーランスを視野に入れたい

理由は「Python初心者のためのおすすめプログラミングスクール3選」で解説しています。