python メモ
一般的なものから, まあ使わんものまで, 見つけたものを追記していく予定.
数値計算
floatの値の小数第一位が0かどうか判定
- float型の変数の整数判定
- 以下で判定. 返り値はboolean
値.is_integer()
階乗
import math math.factorial(x)
累乗
- a**n
pow(a, n)
dictionary
keyが存在しない場合のみ初期化
dictionary.setdefault(key, value)
文字列
listの文字列化
- code
'_'.join(["hoge", "fuga"])
- output
hoge_fuga
英語の小文字, 大文字の判定
- 返り値はbool
x.isupper() x.islower()
英語の小文字, 大文字への変換
x.upper() x.lower()
Unicode コードポイントへの変換, 逆変換
ord(x) chr(x)
IO
listのunpack
- code
list_=[a,b,c,d] print(*lilst_)
- output
a b c d