Easy Tutorial
❮ Python Func Number Tan Python Func Number Floor ❯

Python3 input() Function

Python3 Built-in Functions

The input() function in Python3.x takes a standard input data and returns it as a string.

Note: In Python3.x, raw_input() and input() have been integrated, removing raw_input(), and only the input() function is retained. It accepts arbitrary input, treats all input as a string by default, and returns a string type.

Function Syntax

input([prompt])

Parameter Description:

Example

input() Requires Input of Python Expression

>>> a = input("input:")
input:123                  # Input integer
>>> type(a)
<class 'str'>              # String
>>> a = input("input:")    
input:tutorialpro              # Correct, string expression
>>> type(a)
<class 'str'>             # String

input() Receives Multiple Values

Example

#!/usr/bin/python
# Input the lengths of the three sides of a triangle
a, b, c = (input("Please enter the lengths of the sides of a triangle: ").split())
a = int(a)
b = int(b)
c = int(c)

# Calculate the semi-perimeter p of the triangle
p = (a + b + c) / 2

# Calculate the area s of the triangle
s = (p * (p - a) * (p - b) * (p - c)) ** 0.5

# Output the area of the triangle
print("The area of the triangle is:", format(s, '.2f'))

The output result of the above example is:

Please enter the lengths of the sides of a triangle: 3 4 5
The area of the triangle is: 6.00

More Information

Python2.x input and raw_input() Explanation

Differences Between raw_input() and input() in Python2.x and Python3.x

Python3 Built-in Functions

❮ Python Func Number Tan Python Func Number Floor ❯