Print文の使い方を覚える
Windows
Mac
様々な形式のPrint文を紹介します
「Print=印刷する」という意味がありますが、Pythonでは「Print=コンピュータの画面に文字を出力する」という意味になります
ここでは、文字や数値などの様々な出力例を取り上げて紹介します
print("Hello, world!")
Hello, world!
message = "This is a message"
print(message)
This is a message
number = 100
print(number)
100
message1 = "This is "
message2 = "a message"
print(message1 + message2)
This is a message
x = 1
y = 2
print(str(x) + " + " + str(y) + " = " + str(x + y)) # 数値から文字列の変換を行い、文字列の足し算で表示
print("{0:d} + {1:d} = {2:d}".format(x, y, (x + y))) # 文字列のフォーマット形式で表示
1 + 2 = 3
1 + 2 = 3
print("改行", end="")
print("してません")
改行してません
print("Now Loading ", end="")
for i in range(10):
print(".", end="")
print(" Done!")
Now Loading .......... Done!