Different Imports In Python

In the coding language python, you can import different libraries.

A library is a bit of code that tells python new information to help you solve problems.

(The textbook definition is a collection of functions and methods that allows you to perform lots of actions without writing your own code)

You can import libraries that other coders have built, a wonderful shortcut that helps a lot!

A library allows you access to code that you didn’t have to create yourself, this is a common theme in coding (building on what others have created) and it’s probably one of my favorite things about it. 

There are two main types of importing these libraries into python:

  • a universal import:s imports all of the variables and functions in a library.

Universal imports may look great on the surface, but they’re often not a good idea for one very important reason: they fill your program with all of the variable contained in that library and some of those names overlap with variables in your current code. 

For example, if you have a function of your very own named “sqrt” and you import the math library, this will create a problem. You now have two different functions with the exact same name. Your function is overwritten with what the value that the math library has for “sqrt.”

  • a function import: import only certain variables or functions from a given module. 

If you want to avoid the problem faced when using a universal import, the function import is your friend. A function works like so: from math import *, where you can choose the specific import you want.

Import cautiously, you don’t want to confuse your variables!

Leave a comment