Home > Common Problem > body text

There are several ways to open the root number in python

百草
Release: 2023-07-05 10:49:45
Original
21567 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!