0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

print から始める Python の最初の一歩【Day3】

0
Last updated at Posted at 2025-12-02

Qiita Advent Calendar 2025 のパイソニスタの一人アドカレ Day3 の記事です。

print から始める Python の最初の一歩

Python を始めるうえで、まずは コードを実際に書いて結果を確認することが重要です。
この記事では、Python の最初のステップとして print関数を使った出力の方法をわかりやすく解説します。

1. print関数とは

printPython で値を画面に表示する関数です。
プログラムが正しく動いているか確認したり、結果を表示するのに必須の関数です。

基本の使い方

print("Hello, Python!")
print(100)
print(3.14)

実行すると、ターミナルに書いた値が表示されます。

Hello, Python!
100
3.14

2. 複数の値を表示する

print は複数の値をカンマで区切って渡すこともできます。

print("Python", "学習中", 2025)

出力:

Python 学習中 2025

値の間には自動で半角スペースが入ります。

3. 文字列と数値を組み合わせて表示する

Python 3.6 以降では f文字列(f-string) を使うと簡単に文字列と値を組み合わせて表示できます。

year = 2025
print(f"今年は{year}年です")

出力:

今年は2025年です

4. 改行や区切りの指定

print では改行や文字の区切りを指定できます。

改行なしで表示

print("Python", end="")
print(" 入門")

出力:

Python 入門

区切り文字を指定

print("A", "B", "C", sep="-")

出力:

A-B-C

5. 実際に動かしてみよう

VS Code または任意のテキストファイルに day3.py を作り、次のコードを入力して実行してみてください。

print("Hello, Python!")
print("Python", "学習中", 2025)
year = 2025
print(f"今年は{year}年です")
print("A", "B", "C", sep="-")

ターミナルに以下の結果が表示されれば成功です。

Hello, Python!
Python 学習中 2025
今年は2025年です
A-B-C

6. よくあるミス

  • 引用符(" または ')を閉じ忘れる
print("Hello)  # SyntaxError
  • print のスペルを間違える
pritn("Hello")  # NameError

まとめ

  • print は Python で結果を表示する基本関数
  • 文字列、数値、複数の値、f文字列、改行や区切りの指定ができる
  • まずは手を動かして、出力結果を確認することが最初の一歩

次回 Day4 では、変数定義とデータ型の基本 について解説します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?