Python reverseメソッドでリストを逆順に並べる

環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)

構文
リスト名 = [要素1,要素2,…]
リスト名.reverse()

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
s = ["AA","gg","kk"]
s.reverse()
print (s)
# coding: utf-8 s = ["AA","gg","kk"] s.reverse() print (s)
# coding: utf-8

s = ["AA","gg","kk"]
s.reverse()

print (s)

実行結果
['kk’, 'gg’, 'AA’]

Python

Posted by arkgame