通常你想做:
the_input = input(prompt) # Python 3.x
或者
the_input = raw_input(prompt) # Python 2.x
接着:
print(output) # Python 3.x
或者
print output # Python 2.x
但是,您也可以(但可能不想)这样做:
import sys
the_input = sys.stdin.readline()
bytes_written = sys.stdout.write(output)
这或多或少是在幕后做什么print
和做什么。, (and ) 就像文件一样工作 - 你可以读取和写入它们等。在 Python 术语中,它们被称为类文件对象。input
sys.stdin
sys.stdout
sys.stderr
据我了解,你想要这样的东西:
def f(x, y, z):
return 2*x + y + z + 1
a = int(input("Enter a number: ")) # presuming Python 3.x
b = int(input("Enter another number: "))
c = int(input("Enter the final number: "))
print(f(a, b, c))
如果运行,它看起来像这样:
>>> Enter a number: 7
>>> Enter another number: 8
>>> Enter the final number: 9
>>> 32