Unit2 Input Output
Unit2 Input Output
Unit2 Input Output
>>> x = 12.3456789
>>> print('The value of x is %3.2f' %x)
The value of x is 12.35
>>> print('The value of x is %3.4f' %x)
The value of x is 12.3457
Python Import
• When our program grows bigger, it is a good idea to break it into
different modules.
• 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
print(math.pi)
• Now 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. For example:
>>> from math import pi
>>> pi
3.141592653589793
While importing a module, Python looks at several places defined in sys.path. It is a list of
directory locations.
>>> import sys
>>> sys.path
['', 'C:\\Users\\Deepak\\AppData\\Local\\Programs\\Python\\Python37-32\\Lib\\idlelib',
'C:\\Users\\Deepak\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
'C:\\Users\\Deepak\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
'C:\\Users\\Deepak\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
'C:\\Users\\Deepak\\AppData\\Local\\Programs\\Python\\Python37-32',
'C:\\Users\\Deepak\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages']