eLearning

We are a professional site that will give you the strongest methods to get learn and we will teach you everything about programming and technology

PYTHON

Breaking News

PYTHON
PYTHON
جاري التحميل ...

Python Modules Lesson 11

 Python Modules:



A unit is a set of Python codes (functions, classes ...) that can be easily reused by the programmer, and it can also be called a library.

A module can be imported into your program using the word import with the module name appended. In the following example, we import the time unit that helps in dealing with time in Python, as it provides ready-made functions that enable us to perform several operations, such as getting the current time, as well as the date, etc.

>>> import time

After we have imported the unit of time, we can now access many of the functions and variables in this unit.

For example, we can get the date of the day and the time by calling the asctime function as follows:

>>> import time

>>> time.asctime ()

 'Fri Apr 8 19:47:35 2016'


 The most important modules or libraries in Python are the random and math library

 Firstly random::

 It is the random library in Python that contains ready-made functions that we import as follows:


 >>> import random


The most important functions of the random library:


1-- random ()

Returns a random decimal number between 0.0 and 1.0.


2-- uniform (a, b)

Returns a random decimal between the value we pass in the place of parameter a and the value we pass to it in the place of the parameter b.


3 - randrange ([start,] stop [, step])

Returns a random integer between 0 and the value we pass is the parameter to the stop.


4 - choice (seq)

Returns a random value from among the elements of any sequence we pass to it.


5 - shuffle (x)

We pass a matrix in place of the parameter x, so the positions of its elements are randomly changed.


Second, math library::

It is also a ready-made library in Python that contains functions used in mathematical and engineering operations. We will show some of these functions:


1 - ceil (x)

Returns the larger integer or equal to the number we pass to it in the place of the parameter x.


2 - floor (x)

Returns the smaller integer or equal to the number we pass to it in the place of the parameter x.


3 - pow (x, y)

Returns the result of multiplying the value of the number we pass to it in the place of the parameter x multiplied by the value of the parameter y.


4 - sqrt (x)

The square root of the number we pass to it returns the place of the parameter x.


5 - exp (x)

The exponential value returns the number we pass to it in the place of the parameter x.


6 - sin (x)

The sine value returns the number we pass to it, in place of the parameter x.


7 - cos (x)

The value of cosine returns the number we pass to it, the place of the parameter x.


8 - tan (x)

The tangent returns the number we pass to it, the place of the parameter x.


9 - degrees (x)

The transformation of the number we pass has the place of the parameter x of Degrees.

عن الكاتب

ADMIN

التعليقات


اتصل بنا

If you like the content of our blog, we hope to stay in constant contact, just enter your email to subscribe to the blog express mail so that you will receive the new blog first-hand, and you can send a message by clicking the next button ...

جميع الحقوق محفوظة

eLearning