Python のデータ型
Jason Myers
Instructor
f""cookie_name = "Anzac"
cookie_price = "$1.99"
print(f"Each { cookie_name } cookie costs { cookie_price }.")
"Each Anzac cookie costs $1.99."
"".join() は、呼び出した文字列を区切り文字としてイテラブルを結合しますchild_ages = ["3", "4", "7", "8"]
print(", ".join(child_ages))
"3, 4, 7, 8"
print(f"The children are ages {','.join(child_ages[0:3])}, and {child_ages[-1]}.")
"The children are ages 3, 4, 7, and 8."
.startswith() と .endswith() は、文字列が指定の文字または文字列で始まる・終わるかを判定するメソッドですboy_names = ["Mohamed", "Youssef", "Ahmed"]
print([name for name in boy_names if name.startswith('A')])
["Ahmed"]
in 演算子は、文字列などのイテラブル型の中から指定の値を検索します"long" in "Life is a long lesson in humility."
True
"life" in "Life is a long lesson in humility."
False
.lower() メソッドは文字列を小文字に変換して返します"life" in "Life is a long lesson in humility.".lower()
True
Python のデータ型