Importing and Installing Packages In Python

Importing packages in python is extremely important because you can’t code every contingency for different functions so there are different packages you can use. Packages like datetime help you create alarms because it takes everything we know about the time for example 60 minutes is an hour, there are 24 hours in a day and 60 seconds is a minute and explains it to the computer in one word whenever you put it in your code. To import packages first you will need to install the packages you want. To do this python has a function called pip, to check it is installed (pip is downloaded with python) type in python –version in the terminal. To get to the terminal open the command prompt by pressing the Windows key and typing command prompt.

Now you can download any package. Now go to pycharm and open a new project, and at the bottom of the window click on the terminal.

Once you open up the terminal now it is time to add a package to do this just type in pip and the package you want. In our case, we will download the datetime package; so it would be pip install datetime and then click enter.

Now once you downloaded the package you can import the package in your code; import datetime.

You can also change how you represent DateTime in your code for example instead of typing print(DateTime) you can change your import statements to import DateTime as time and then your print statement would look like: print(time).

CONGRATS! You can now import different packages.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

cheetahlion2018


0
Would love your thoughts, please comment.x
()
x