Home >Common Problem >There are several ways to open the root number in python

There are several ways to open the root number in python

百草
百草Original
2023-07-05 10:42:2422848browse

How to open the root in python: 1. Use the "**" power function symbol; 2. Use the "sqrt" function, which requires importing the math library. The direct function of this function is to open the root without adding other parameters. , if the square root of a complex number is calculated, that is, when the parameter value is less than 0, you need to use the "sqrt" of the cmath library; 3. Use the built-in "pow" function, "pow(x, y)" is used to find the y power of x .

There are several ways to open the root number in python

The operating system for this tutorial: Windows 10 system, Python version 3.11.2, DELL G3 computer.

There are several ways to open the root number in python

How to open the root number in Python:

1. Use the exponentiation symbol

Use 0.5 power Indicates opening the root.

a = 9 ** 0.5
# 3.0

2. Use the sqrt function

To use the sqrt function, you need to import the math library. The direct function of this function is to open the root without adding other parameters.

import math
a = math.sqrt(9)# 3.0

If you are calculating the square root of a complex number, that is, when the parameter value is less than 0, you need to use the sqrt of the library cmath, as follows:

import cmath
a = cmath.sqrt(-10)
# 3.1622776601683795j

3. Use the built-in function pow

Built-in The function pow(x, y) is used to find the y power of x. The root operation can be written in the following form.

a = pow(9, 0.5)
# 3.0

Python was designed in the early 1990s by Guido van Rossum of the Dutch Society for Mathematics and Computer Science as a replacement for a language called ABC. [Python provides efficient high-level data structures and allows simple and effective object-oriented programming. Python's syntax and dynamic typing, as well as the nature of an interpreted language, make it a programming language for scripting and rapid application development on most platforms. With the continuous update of the version and the addition of new language features, it is gradually used for independent, large-scale Project development.

Python is more suitable for novices to learn among various programming languages. The Python interpreter is easy to extend and can be extended with new functions and data types using C language or C (or other languages ​​that can be called through C). Python can also be used as an extension programming language in customizable software. Python's rich standard library provides source code or machine code suitable for each major system platform.

The above is the detailed content of There are several ways to open the root number in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn