Python I/O and Import
Python I/O means to handle input and output operations like read data from any input devices using like input() function and after performing operations based on functions written inside and produces some output through output module like print() function.
Demo Program:
A simple program(mainly two lines) to ask the user to enter your name and producing a greeting message to the console or output.
name=str(input("Please enter your name"))
print("Hello "+name)
Import Keyword:
In python, the import is a built-in keyword which is used to import modules in python or any other third party packages. So let's demonstrate this process for both purposes like an internal module or external packages.
Demo Program:
If you want to work with Regular Expressions so you need to import python built-in package re.
Program 1 (Built-in python package): Print a list of matched
import re
words = "The season is very cold"
matches= re.findall("is", words)
print(matches)
Program 2 (Third-party python packages): Read CSV file using the pandas library
Step 1: Install the library using a python-pip command
pip install pandas
Step 2: Import pandas library using below command like
import pandas as pd
Step3: Make sure you have a sample CSV file in your current working directory
# Import pandas library
import pandas as pd
# reading csv file
df=pd.read_csv("sample.csv")
#print the data
print(df)
Checkout Related Articles