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?

【Python】input()とは

Posted at

input()は、Pythonの組み込み関数の一つで、ユーザーからの入力を受け取るために使用されます。この関数を使うことで、プログラムが実行中にユーザーがキーボードから入力したデータを取得することができます。

基本的な使い方

user_input = input("メッセージを表示: ")

上記の例では、input()関数が呼び出されると、指定したメッセージ(この場合は「メッセージを表示: 」)が表示され、ユーザーが何かを入力するのを待ちます。
ユーザーが入力を終えてEnterキーを押すと、その入力が文字列として返され、user_inputに格納されます。

name = input("あなたの名前を入力してください: ")
print(f"こんにちは、{name}さん!")

このコードを実行すると、ユーザーに名前を入力するように促し、入力された名前を使って挨拶を表示します。

注意点
input()は常に文字列を返します。もし数値として扱いたい場合は、int()やfloat()などで変換する必要があります。
Python 2.xでは、input()は異なる動作をするため、Python 3.xを使用していることを確認してください。
このように、input()はユーザーからのデータを受け取るための非常に便利な機能です。

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?