まぬねこの足跡。。。

備忘録+たのしさ+ひっそりと

Python3

Python - str.isnumeric():1文字以上、全数字か

概要 実行結果 表示イメージ 概要str.isnumeric() 1文字以上、全数字か 組込み型 文字列メソッド 実行結果 print("1234".isnumeric()) print("abc".isnumeric()) print("%abc".isnumeric()) print("%Abc".isnumeric()) print("あいう".isnumeric()) 表示イメ…

Python - str.islower():1文字以上、全英小文字か

概要 実行結果 表示イメージ 概要str.islower() 1文字以上、全英小文字か ※大小文字があるもの全部 組込み型 文字列メソッド 実行結果 print("abc".islower()) print("%abc".islower()) print("%Abc".islower()) print("あいう".islower()) print("1234".isl…

Python - str.isidentifier():有効な識別子(変数,関数,クラスなどの名)か

概要 実行結果 表示イメージ 概要str.isidentifier() 有効な識別子(変数,関数,クラスなどの名)か 組込み型 文字列メソッド ちょこっとメモ識別子 命名規則 大小英数字、「_」アンダースコア ※2バイト文字もOK 先頭に数字はNG 実行結果 print("abc_1".isidentifier()…

Python - str.isdigit():1文字以上、全数字か

概要 実行結果 表示イメージ 概要str.isdigit() 組込み型 文字列メソッド 実行結果 inte = '123456' print(inte.isdigit()) flotA = '0x1dfe' print(flotA.isdigit()) flotB = '123.456' print(flotB.isdigit()) strg = 'あいうえお' print(strg.isdigit()) …

Python - str.isdecimal():1文字以上、10進数字か

概要 実行結果 表示イメージ 概要str.isdecimal() 1文字以上、10進数字か 組込み型 文字列メソッド 実行結果 inte = '123456' print(inte.isdecimal()) flotA = '0x1dfe' print(flotA.isdecimal()) flotB = '123.456' print(flotB.isdecimal()) strg = 'あい…

Python - str.isascii():空字または全ascii文字か

概要 実行結果 表示イメージ 概要str.isascii() 空字または全ascii文字か 組込み型 文字列メソッド 実行結果 eng= 'aAcdefg' print(eng.isascii()) eng= 'a2bcdefg' print(eng.isascii()) eng= 'abc-defg' print(eng.isascii()) strg = 'アイウエオ' print(strg.i…

Python - str.isalpha():1文字以上、全英字か

概要 実行結果 表示イメージ 概要str.isalpha() 1文字以上、全英字か 日本語は全半角共にencode('utf-8')で変換必要。 組込み型 文字列メソッド 実行結果 eng= 'aAcdefg' print(eng.isalpha()) eng= 'a2bcdefg' print(eng.isalpha()) eng= 'abc-defg' print(…

Python - str.isalnum():1文字以上、全英数字か

概要 実行結果 表示イメージ 概要str.isalnum() 1文字以上、全英数字か 日本語は全半角共にencode('utf-8')で変換必要。 組込み型 文字列メソッド 実行結果 eng= 'aAcd1e2fg' print(eng.isalnum()) eng= 'abc-defg' print(eng.isalnum()) strg = 'アイウエオ' pri…

Python - str.index(sub[, start[, end]]):文字位置 (ない時:ValueError)

概要 実行結果 表示イメージ 概要str.index(sub[, start[, end]])sub:検査文字 start,end:スライスと同一 文字位置 ない時:ValueError 組込み型 文字列メソッド 実行結果 eng= 'abcdefg' print(eng.index('c')) print(eng.index('z')) 表示イメージ 2 ---…

Python - str.format_map(mapping):フォーマット(dictコピー無)

概要 実行結果 表示イメージ 概要str.format_map(mapping) フォーマット(dictコピー無) mapping が dict のサブクラスの時利用。 組込み型 文字列メソッド 実行結果 class Name(dict): def __missing__(self, nam): return nam '{fruit}がおいしい'.format_m…

Python - str.format(*args, **kwargs):フォーマット

概要 実行結果 表示イメージ 概要str.format(*args, **kwargs) フォーマット 組込み型 文字列メソッド 実行結果 'みかんが{0}個'.format(1000) 表示イメージ みかんが1000個

Python - str.find(sub[, start[, end]]):文字位置

概要 実行結果 表示イメージ 概要str.find(sub[, start[, end]])sub:検査文字 start,end:スライスと同一 文字位置 文字列が見つからない時「-1」 組込み型 文字列メソッド 実行結果 eng= 'abcdefg' print(eng.find('c')) print(eng.find('z')) print(eng.fin…

Python - str.expandtabs(tabsize=8):タブ文字をスペースで整列

概要 実行結果 表示イメージ 概要str.expandtabs(tabsize=8)tabsize:タブ位置 全タブ文字がスペースで置換 組込み型 文字列メソッド 実行結果 num='ab\tabc\tabcd\tabcdef' print(num.expandtabs()) print(num.expandtabs(4)) print(num.expandtabs(2)) 表…

Python - str.endswith(suffix[, start[, end]]):文字列の最後が指定文字でおわるか

概要 実行結果 表示イメージ 概要str.endswith(suffix[, start[, end]])suffix:対象文字 start,end:スライスと同一 文字列の最後が指定文字でおわるか 組込み型 文字列メソッド 実行結果 eng1 = 'abcdefg' print(eng1.endswith('g')) print(eng1.endswith(…

Python - str.encode(encoding='utf-8', errors='strict'):バイト単位でエンコード

概要 実行結果 表示イメージ 概要str.encode(encoding='utf-8', errors='strict') バイト単位でエンコード 組込み型 文字列メソッド 実行結果 eng= 'abcdefg' print(eng.encode()) 表示イメージ b'abcdefg'

Python - str.count(sub[, start[, end]]):出現回数 重複なし

概要 実行結果 表示イメージ 概要str.count(sub[, start[, end]])sub:出現文字 start,end:スライスと同一 出現回数 重複なし 組込み型 文字列メソッド 実行結果 eng= 'abccccg' print(eng.count('c')) print(eng.count('c',1,3)) 表示イメージ 4 1

Python - str.center(width[, fillchar]):文字列を中央に、他を埋める

概要 実行結果 表示イメージ 概要str.center(width[, fillchar]) 文字列を中央に、他を埋める 文字列がwidthより短いとそのまま返す。 組込み型 文字列メソッド 実行結果 eng1 = 'abcdefg' print(eng1.center(10,'z')) print(eng1.center(1,'z')) # 文字の長…

Python - str.casefold():casefold(大小文字区別なし)に変換

概要 実行結果 表示イメージ 概要str.casefold() casefold(大小文字区別なし)に変換 見た目は小文字 組込み型 文字列メソッド 実行結果 eng1 = 'abcdefg' eng2 = 'ABCDEFG' print(eng1.casefold()) print(eng2.casefold()) 表示イメージ abcdefg abcdefg

Python - str.capitalize():頭文字のみ大文字 変換

概要 実行結果 表示イメージ 概要str.capitalize() 頭文字のみ大文字 組込み型 文字列メソッド 実行結果 eng1 = 'abcdefg' print(eng1.capitalize()) 表示イメージ Abcdefg

数学ライブラリ math

数値 数表現 判定 計算 集合 指数関数 対数関数 三角関数 ※ラジアンで指定。※戻り値もラジアン 2点間の直線距離 角度変換 ラジアン⇄角度 双曲線関数 特殊関数 定数 数値 Python - math.inf:無限大 数表現 Python - math.fabs(x):絶対値 Python - math.ceil…

Python - math.nan:浮動小数点型(非数値)nanの値

概要 インポート 実行結果 表示イメージ 概要nan 浮動小数点型(非数値)Nanの値 mathモジュール インポート import math 実行結果 import math print(math.nan) 表示イメージ nan

Python - math.inf:浮動小数の正の無限大

概要 インポート 実行結果 表示イメージ 概要inf 浮動小数の正の無限大 mathモジュール インポート import math 実行結果 import math print(math.inf) 表示イメージ inf

Python - math.tau:円定数Tau(2π)「円周と半径の比」

概要 インポート 実行結果 表示イメージ 概要tau 円定数Tau(2π)「円周と半径の比」 mathモジュール インポート import math 実行結果 import math print(math.tau) 表示イメージ 6.283185307179586

Python - math.e:自然対数の底

概要 インポート 実行結果 表示イメージ 概要e 自然対数の底 mathモジュール インポート import math 実行結果 import math print(math.e) 表示イメージ 2.718281828459045

Python - math.pi:円周率

概要 インポート 実行結果 表示イメージ 概要pi 円周率 mathモジュール インポート import math 実行結果 import math print(math.pi) 表示イメージ 3.141592653589793

Python - math.lgamma(x):ガンマ関数で絶対値の自然対数

概要 インポート 実行結果 表示イメージ 概要lgamma(x) ガンマ関数で絶対値の自然対数 mathモジュール インポート import math 実行結果 import math print(math.lgamma(1)) print(math.lgamma(2)) print(math.lgamma(3)) 表示イメージ 0.0 0.0 0.6931471805…

Python - math.gamma(x):ガンマ関数

概要 インポート 実行結果 表示イメージ 概要gamma(x) ガンマ関数 mathモジュール ちょこっとメモガンマ関数(複素階乗)階乗を一般化する関数。複素数全体におよぶ。 インポート import math 実行結果 import math print(math.gamma(1)) print(math.gamma(2))…

Python - math.erfc(x):相補誤差関数

概要 インポート 実行結果 表示イメージ 概要erfc(x) 相補誤差関数 (記号:「erfc」) 1-xが桁落ちのとき(x=大きな数) に利用。 mathモジュール インポート import math 実行結果 import math print(math.erfc(1)) print(math.erfc(0)) print(math.erfc(-1…

Python - math.erf(x):誤差関数

概要 インポート 実行結果 表示イメージ 概要erf(x) 誤差関数 mathモジュール ちょこっとメモ誤差関数(ガウスの誤差関数)数学におけるシグモイド形状の特殊関数。記号:「erf 」インポート import math 実行結果 import math print(math.erf(1)) print(math.…

Python - math.atanh(x):逆双曲線正接(アークハイパボリックタンジェント)

概要 インポート 実行結果 表示イメージ 概要atanh(x) -1<x<1 逆双曲線正接 mathモジュール インポート import math 実行結果 import math print(math.atanh(0.5)) print(math.atanh(0)) print(math.atanh(-0.5)) 表示イメージ 0.5493061443340548 0.0 -…