組み込み関数
組み込み関数:importしなくとも使える関数
- print(値1, 値2,..., sep = "区切り文字", end = "行末文字")
- type(変数)
- 型変換
- max(数値1, 数値2,...) / min(数値1, 数値2,...)
- len(イテラブル)
- round(数値, 桁数)
- input("表示文字列")
- range( 開始値, 終了値, ステップ)
- isinstance(変数, (type, type,...))
- リスト内の検索 : in / index()
print(値1, 値2,..., sep = "区切り文字", end = "行末文字")
a = 100 b = 200 c = 300 abc = a + b + c print(a, b, c, sep = "、", end = "/以上") print(abc) # 100、200、300/以上600
type(変数)
a = "test" print(type(a)) # <class 'str'> b = 123 print(type(b)) # <class 'int'> c = 0.123 print(type(c)) # <class 'float'> d = True print(type(d)) # <class 'bool'> e = [a,b,c] print(type(e)) # <class 'list'> f = (a,b,c) print(type(f)) # <class 'tuple'> g = {a,b,c} print(type(g)) # <class 'set'> h = {1:"aa", 2:"bb"} print(type(h)) # <class 'dict'>
型変換
a = 123 print("string:" + str(a)) # stringにintのままでは接続できない b = "456" print(1000 + int(b))
max(数値1, 数値2,...) / min(数値1, 数値2,...)
print(max(1, 9, 3, 6.3)) # 9 print(min(1, 9, 3, 6.3)) # 1
len(イテラブル)
print(len("テスト123")) # 6 list = ["aa", "bb", "cc", "dd"] print(len(list)) # 4
round(数値, 桁数)
print(round(100.3)) # 100 print(round(100.5)) # 5は切捨て # 100 print(round(100.876, 2)) # 100.88
input("表示文字列")
t = input("入力して下さい") print(t + "!!!") # 入力して下さい # "{入力文字}!!!"
range( 開始値, 終了値, ステップ)
for i in range(10, 20, 2): # 終了値は19になる print(i) # 10 # 12 # 14 # 16 # 18
isinstance(変数, (type, type,...))
a = "test" b = 12.3 print(isinstance(a,(int,float))) # False print(isinstance(b,(int,float))) # True
リスト内の検索 : in / index()
colors = ["red", "blue", "yellow", "black", "blue"] print("yellow" in colors) # True print(colors.index("black")) # 3