>>> print('This sentence is output to the screen') This sentence is output to the screen >>> a = 5 >>> print('The value of a is',a) The value of a is 5
Input In Python, we have the input() function to allow this. The syntax for input() is input([prompt]) where prompt is the string we wish to display on the screen. It is optional.
>>> num = input('Enter a number: ') Enter a number: 10 >>> num '10'Import A module is a file containing Python definitions and statements. Python modules have a filename and end with the extension .py. Definitions inside a module can be imported to another module or the interactive interpreter in Python. We use the import keyword to do this. For example, we can import the math module by typing in import math.
>>> import math >>> math.pi 3.141592653589793Now all the definitions inside math module are available in our scope. We can also import some specific attributes and functions only, using the from keyword.
>>> from math import pi >>> pi 3.141592653589793