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
جاري التحميل ...

Numbers in python Lesson 6

Numbers in python Lesson 6:



Number data types store numerical values. They are immutable data types, which means that changing the value of the numbers data type results in a newly customized object.

Number objects are created when a value is assigned to them. For example -

var1 = 1

 var2 = 10

You can also delete the reference to a number object using the del clause. The del syntax is -

del var1 [, var2 [, var3 [...., varN]]]]

You can delete a single object or multiple objects using the del statement. For example -

var

var_a, var_b

Python supports four different digital types -

int (signed integers) - often called only integers or ints, they are positive or negative integers with no decimal point.

long (long integers) - also called longs, are infinite integers, written as integers followed by an uppercase or lowercase letter L.

float (floating point real values) - also called floats, they represent real numbers and are written with a decimal that divides the integer and fractional parts. Floats may also be scientific notation, where E or e denotes strength 10 (2.5e2 = 2.5 x 102 = 250).

Complex (complex numbers) - from the form a + bJ, given a, b, and J (or j) representing the square root of -1 (which is an imaginary number). The real part of the number is, the imaginary part is B. Complex numbers are not often used in Python programming.

The Python programming language allows you to use a lowercase L letter with a long variable, but it is recommended to use only a large L to avoid confusion with the number 1. Python displays long integers with uppercase L letters.

A complex number consists of an ordered pair of real floating-point numbers denoted by + bj, where it represents the real part and b is the imaginary part of the complex number.

Number type conversion

Python internally converts numbers in an expression containing mixed types into a common type for evaluation. But sometimes, you need to explicitly force a number from one type to another to satisfy the requirements of a function parameter or operator.

To convert variable x into an ordinary integer type:

int (x)

To convert x to a long integer, write:

long (x)

To convert x to a floating-point number, type:

float (x)

To convert x to a complex number with a real part x and an imaginary part zero, write:

complex (x)

Converts x and y into a complex number with a real part x and an imaginary part y. Numeric expressions x and y type:

complex (x, y)

Mathematical functions in Python

Python includes the following functions that perform math operations.

* Function and Description 1 abs (x)

Absolute value of x: the (positive) distance between x and zero.

2ceil (x)

X ceiling: the smallest integer not less than x

3cmp (x, y)

Negative one if x is less than y and zero if x is equal to y or one if x is greater than y.

4exp (x)

Exponential x: ex

5fabs (x)

The absolute value of x.

6floor (x)

Floor x: the largest integer no more than x

7log (x)

Natural logarithm of x, of x> 0

8log10 (x)

Base logarithm 10 of x of x> 0.

9max (x1, x2, ...)

Its biggest argument: the value closest to positive infinity

10min (x1, x2, ...)

Its smallest argument: the value closest to negative infinity

11modf (x)

The fractional and integer parts of x in the two-element layer. Both parts have the same x. The integer portion is returned as afloat.

12pow (x, y)

The x ** y value.

13round (x [, n])

Round x to the n digits of the decimal point. Python rounds to zero as a breakeven: round (0.5) is 1.0 and round (-0.5) is -1.0.

14sqrt (x)

The square root of x of x> 0

Random number functions

Random numbers are used for gaming, simulation, testing, security, and privacy applications. Python contains the following functions.

* Function and description: 1 choice (seq)

A random item from a list, string, or text.

2randrange ([start,] stop [, step])

Randomly selected item from the range (start, end, step)

3random ()

A random float r, such as 0 is less than or equal to r and r is less than 1

4seed ([x])

Sets the correct starting value used to generate random numbers. Call this function before calling any other random unit function. Return none.

5shuffle (lst)

Randomly list items in place. Returns none.

6uniform (x, y)

A random float r, such that x is less than r or equal to r and r is less than y

Trigonometric functions

Python includes the following functions that perform trigonometric arithmetic operations.

* Function and Description 1 acos (x)

Returns the arcsine of x cosine, with radius.

2asin (x)

Returns the arc sine of x, times the radius.

3atan (x)

Returns the arctangent from x, times the radius.

4atan2 (y, x)

Return atan (r / o), at radius.

5cos (x)

Returns the cosine of x the radius.

6hypot (x, y)

Returns the Euclidean base, sqrt (x * x + y * y).

7sin (x)

Returns the sine of the radius x.

8tan (x)

Returns the tangent of the radius x.

9degrees (x)

Converts angle x from radius to degrees.

10radians (x)

Converts angle x from degrees to radius.

Mathematical constants

The model also knows two mathematical constants

* Constants and Description 1

pi

The mathematical P constant.

2--

e

Mathematical constant e

عن الكاتب

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