Some Modules In Python how to it works

Categories: Python

Some Modules In Python how to it works 

 

To do almost any useful science with Python, you will need to load various libraries, known as ”modules.” Actually, a module can be just an ordinary Python script, which defines various functions and other things that are not provided by the core language. A module can also provide access to high-performance extensions written using compiled languages.

To make use of a module with name myModule, you just type: import myModule. Members of the module are accessed by prepending the module name to the memer name, separated by a ”.”. For example, if myModule contains the constant r earth, and the function sza, these constant is accessed using myModule.r earth and the function is evaluated at t using myModule.sza(t). If you don’t need to keep the module’s members separate, you can avoid the need of prepending the module name

by using from myModule import *.

The standard math functions are in the module math, and you make them available by typing import math. To see what’s there, type dir(math); this works for any module. Now, to compute sin(π/7.) for example, you type math.sin(math.pi/7.).

To find out more about the function math.sin, just type help(math.sin). If you don’t like typing math.sin, you can import the module using from math import * instead, and then you can just use sin,cos, etc. without the prefix.

Top Blogs
Interview Question and Answer of Python Published at:- Basic Concepts of Python Programming Published at:- Learn Python Programming Language Published at:- Let’s know about Python basics Published at:- Let’s know about the Python Shell and idle Published at:- How to running Python Locally Published at:- What is Lists, tuples and strings in Python? Published at:- Some Modules In Python how to it works Published at:- Program control: Looping, conditionals and functions Published at:- Program control: Looping, conditionals and functions ( Part 2) Published at:- Top iOS interview questions for Beginners Published at:-
R4Rin Team
The content on R4Rin.com website is created by expert teams.