プレイ回数
5
Pythonで使えるやつ
用語一覧(115件)
print("Hello, player!")
print("Hello, player!")
挨拶を出力する
name = "Python user"
name = "Python user"
変数に名前を代入
age = 30
age = 30
変数に年齢を代入
if x > 10:
if x > 10:
条件分岐の開始
for i in range(5):
for i in range(5):
ループ処理の開始
def func_name():
def func_name():
関数を定義する
my_list = [1, 2, 3]
my_list = [1, 2, 3]
リストを作成
import math
import math
mathモジュールをインポート
data = {"key": "value"}
data = {"key": "value"}
辞書を作成
result = a + b
result = a + b
足し算の結果
print(f"Name: {name}")
print(f"Name: {name}")
f文字列で出力
num = int(input())
num = int(input())
入力を整数に変換
if True:
if True:
真の場合の条件
for item in my_list:
for item in my_list:
リストの要素をループ
return True
return True
Trueを返す
my_tuple = (1, 2)
my_tuple = (1, 2)
タプルを作成
from datetime import date
from datetime import date
日付をインポート
count = len(my_list)
count = len(my_list)
リストの長さを取得
x = 10 / 2
x = 10 / 2
割り算の結果
while True:
while True:
無限ループ
print("Done!")
print("Done!")
完了を出力
text = "Python is fun."
text = "Python is fun."
文字列を代入
price = 99.99
price = 99.99
浮動小数点数
elif y < 5:
elif y < 5:
別の条件
break
break
ループを抜ける
class MyClass:
class MyClass:
クラスを定義
my_set = {1, 2, 3}
my_set = {1, 2, 3}
セットを作成
import random
import random
randomモジュールをインポート
message = "Hi" + "!"
message = "Hi" + "!"
文字列結合
is_active = False
is_active = False
真偽値
print(x * y)
print(x * y)
掛け算の結果
value = None
value = None
Noneを代入
try:
try:
エラー処理開始
except ValueError:
except ValueError:
値エラーをキャッチ
finally:
finally:
必ず実行
class NewClass(MyClass):
class NewClass(MyClass):
クラスを継承
add(a, b)
add(a, b)
関数呼び出し
abs_val = abs(-5)
abs_val = abs(-5)
絶対値
max_num = max(1, 5)
max_num = max(1, 5)
最大値
min_num = min(1, 5)
min_num = min(1, 5)
最小値
round(3.14)
round(3.14)
四捨五入
sum_val = sum([1, 2])
sum_val = sum([1, 2])
合計値
type(my_list)
type(my_list)
型を調べる
range(10)
range(10)
レンジオブジェクト
enumerate(my_list)
enumerate(my_list)
インデックス付きループ
zip(list1, list2)
zip(list1, list2)
複数のリストを結合
sorted(my_list)
sorted(my_list)
ソートされたリスト
reversed(my_list)
reversed(my_list)
逆順リスト
all([True, False])
all([True, False])
全て真か
any([True, False])
any([True, False])
どれか真か
bool(0)
bool(0)
真偽値に変換
chr(97)
chr(97)
数値から文字へ
ord('a')
ord('a')
文字から数値へ
divmod(10, 3)
divmod(10, 3)
商と余り
format(123, '04d')
format(123, '04d')
書式設定
hex(255)
hex(255)
16進数に変換
oct(255)
oct(255)
8進数に変換
pow(2, 3)
pow(2, 3)
べき乗
input("Enter name: ")
input("Enter name: ")
入力を促す
open("file.txt", "r")
open("file.txt", "r")
ファイルを開く
with open("f.txt") as f:
with open("f.txt") as f:
ファイルを安全に開く
f.read()
f.read()
ファイルを読み込む
f.write("data")
f.write("data")
ファイルに書き込む
json.dumps(data)
json.dumps(data)
JSONに変換
json.loads(text)
json.loads(text)
JSONを読み込む
requests.get(url)
requests.get(url)
GETリクエスト
response.status_code
response.status_code
ステータスコード
pd.DataFrame()
pd.DataFrame()
データフレームを作成
np.array([1, 2])
np.array([1, 2])
NumPy配列作成
import pandas as pd
import pandas as pd
pandasをインポート
import numpy as np
import numpy as np
numpyをインポート
sys.exit()
sys.exit()
プログラムを終了
os.listdir('.')
os.listdir('.')
ディレクトリの内容
re.search("pat", "txt")
re.search("pat", "txt")
正規表現検索
datetime.now()
datetime.now()
現在日時
time.sleep(1)
time.sleep(1)
1秒待機
class Dog:
class Dog:
犬クラス
dog = Dog()
dog = Dog()
Dogのインスタンス
dog.bark()
dog.bark()
吠えるメソッド
try: pass
try: pass
tryブロック
except: pass
except: pass
exceptブロック
lambda x: x * 2
lambda x: x * 2
ラムダ関数
map(func, my_list)
map(func, my_list)
関数を適用
filter(func, my_list)
filter(func, my_list)
フィルタリング
reduce(func, list)
reduce(func, list)
リストを削減
set([1, 2, 3])
set([1, 2, 3])
セットを作成
tuple([1, 2])
tuple([1, 2])
タプルに変換
list("abc")
list("abc")
リストに変換
str(123)
str(123)
文字列に変換
int("123")
int("123")
整数に変換
float("1.23")
float("1.23")
浮動小数点数に変換
bool("")
bool("")
空文字列はFalse
dir(my_object)
dir(my_object)
オブジェクトの属性
help(print)
help(print)
関数のヘルプ
isinstance(x, int)
isinstance(x, int)
型のチェック
issubclass(A, B)
issubclass(A, B)
継承関係のチェック
next(iterator)
next(iterator)
次の要素を取得
iter(my_list)
iter(my_list)
イテレータを作成
super().__init__()
super().__init__()
親クラスの初期化
@classmethod
@classmethod
クラスメソッドデコレータ
@staticmethod
@staticmethod
スタティックメソッドデコレータ
property
property
プロパティデコレータ
raise ValueError
raise ValueError
エラーを発生させる
assert x == y
assert x == y
アサート文
del my_list[0]
del my_list[0]
要素を削除
from collections import Counter
from collections import Counter
カウンタをインポート
Counter("abc")
Counter("abc")
文字を数える
deque([1,2,3])
deque([1,2,3])
両端キュー
OrderedDict()
OrderedDict()
順序保持辞書
defaultdict(list)
defaultdict(list)
デフォルト辞書
namedtuple('Point','x y')
namedtuple('Point','x y')
名前付きタプル
import os, sys
import os, sys
複数モジュールインポート
import json
import json
jsonをインポート
import re
import re
正規表現をインポート
import time
import time
timeをインポート

