Closed1

演習問題の間違えたところ確認用

naonao

正解率 20/40 あと半分

間違えたところのメモ
1.クラス内のと特殊メソッド

    def __str__(self):
    文字列型の変換内容を決める
        return f"出力文字"

2.enumの評価
enumの評価は同じインスタンスで同じ値ならtrueになる

class Sample(enum.Enum):
    HOGE = 1
    FUGA = 1
    HOGEFUFGA = 3

sample = Sample.HOGE
print("HOGE" == sample.name) # True
print(Sample.HOGE == Sample.FUGA) # True

3.return値の複数個(tuple)受け取り

def sample():
    a, b, c = 1, 2, 3
    return a, b, c
print(sample())
e, f, g = sample()  # unpack
print(e, f, g)

4.辞書型のキーと値のペアを取り出すときに使用するのはitems()

dict.keys() # キーをすべて返す
dict.values() # バリューをすべて返す
dict.items() # キーと値のペアをすべて返す

5.itertools.chain()
引数で渡されたイテラブルオブジェクトを連結する
int型は×

it = itertools.chain([1, 2, 3], [4, 5, 6], "789")
for i in it:
    print(i) # 1,2,3,4,5,6,7,8,9

このスクラップは2024/11/19にクローズされました