Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
MySQL クエリの結果を 1 つの変数に格納したい (Python)
sql = "SELECT * FROM movies" result = cursor.fetchall() for row in result: movies = row[1] print(movies)
(最後の行のみを印刷します)
movies = row[1]ここmoviesに変数があり、forループの最後の要素のみが含まれます。
movies = row[1]
movies
リストを作成する必要がありますmovies
movies = []
そして、やります
for row in result: movies.append(row[1]) print(movies)