Hướng dẫn how to import power function in python - cách nhập hàm nguồn trong python

Phương pháp toán học


Thí dụ

Tìm giá trị của 9 được nâng lên công suất của 3:

# Nhập thư viện toán học
import math

#Return Giá trị của 9 được nâng lên thành sức mạnh của 3Print (Math.pow (9, 3))
print(math.pow(9, 3))

Hãy tự mình thử »


Định nghĩa và cách sử dụng

Phương pháp math.pow() trả về giá trị của x được nâng lên cho sức mạnh y.

Nếu x là âm và y không phải là một số nguyên, nó sẽ trả về giá trịerror.

Phương pháp này chuyển đổi cả hai đối số thành một float.

Mẹo: Nếu chúng ta sử dụng math.pow(1.0,x) hoặc math.pow(x,0.0), nó sẽ luôn trả về 1.0. If we use math.pow(1.0,x) or math.pow(x,0.0), it will always returns 1.0.


Cú pháp

Giá trị tham số

Tham sốSự mô tả
xYêu cầu. Một số đại diện cho cơ sở
yYêu cầu. Một số đại diện cho số mũ

Chi tiết kỹ thuật

Giá trị trở lại:Giá trị float, biểu thị giá trị của x với công suất của y (xy)

Phương pháp toán học


❮ Chức năng tích hợp sẵn


Thí dụ

Trả lại giá trị 4 cho công suất của 3 (giống như 4 * 4 * 4):

x = pow (4, 3)

Hãy tự mình thử »


Định nghĩa và cách sử dụng

Hàm pow() trả về giá trị của x cho công suất của y (xY).

Nếu có tham số thứ ba, nó sẽ trả lại x cho sức mạnh của y, mô đun z.


Cú pháp

Giá trị tham số

Tham sốSự mô tả
xMột số, cơ sở
yMột số, số mũ
zKhông bắt buộc. Một số, mô đun

Nhiều ví dụ hơn

Thí dụ

Trả lại giá trị 4 cho công suất của 3 (giống như 4 * 4 * 4):

x = pow (4, 3)

Hãy tự mình thử »

❮ Chức năng tích hợp sẵn


Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc returns the result of the first parameter raised to the power of the second parameter.

    Bàn luận

    Python3

    Output:

    9

    Hàm python pow () trả về kết quả của tham số đầu tiên được nâng lên công suất của tham số thứ hai.

    Ví dụ về chức năng Python pow ()pow(x, y, mod)

    Python pow () Chức năng cú pháp

    • Cú pháp: POW (X, Y, Mod) Number whose power has to be calculated.
    • Tham số: & nbsp; Value raised to compute power.
    • X: Số có công suất phải được tính toán.if provided, performs modulus of mod on the result of x**y (i.e.: x**y % mod)

    Y: Giá trị tăng lên để tính năng lượng.Returns the value x**y in float or int (depending upon input operands or 2nd argument).

    Mod [Tùy chọn]: Nếu được cung cấp, hãy thực hiện mô đun của mod về kết quả của x ** y (tức là: x ** y % mod)three arguments

    Python3

    print(

    The value of (3**4) % 10 is : 1
    0
    The value of (3**4) % 10 is : 1
    1
    The value of (3**4) % 10 is : 1
    2
    The value of (3**4) % 10 is : 1
    3

    print(

    The value of (3**4) % 10 is : 1
    6(
    The value of (3**4) % 10 is : 1
    8
    The value of (3**4) % 10 is : 1
    9
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    0
    The value of (3**4) % 10 is : 1
    9
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    2
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    3

    Output:  

    The value of (3**4) % 10 is : 1

    Giá trị trả về: & nbsp; trả về giá trị x ** y trong float hoặc int (tùy thuộc vào toán hạng đầu vào hoặc đối số thứ 2). 

    Hướng dẫn how to import power function in python - cách nhập hàm nguồn trong python

    Python3

    print(

    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    6
    The value of (3**4) % 10 is : 1
    1
    The value of (3**4) % 10 is : 1
    2
    The value of (3**4) % 10 is : 1
    3

    print(

    The value of (3**4) % 10 is : 1
    6(
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    0
    The value of (3**4) % 10 is : 1
    9
    The value of (3**4) % 10 is : 1
    8
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    3

    print(math.pow(1.0,x)0

    The value of (3**4) % 10 is : 1
    1
    The value of (3**4) % 10 is : 1
    2
    The value of (3**4) % 10 is : 1
    3

    print(

    The value of (3**4) % 10 is : 1
    6(math.pow(1.0,x)8
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    0
    The value of (3**4) % 10 is : 1
    9
    The value of (3**4) % 10 is : 1
    8
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    3

    print(math.pow(x,0.0)5

    The value of (3**4) % 10 is : 1
    1
    The value of (3**4) % 10 is : 1
    2
    The value of (3**4) % 10 is : 1
    3

    Các

    print(pow()0

    The value of (3**4) % 10 is : 1
    1
    The value of (3**4) % 10 is : 1
    2
    The value of (3**4) % 10 is : 1
    3

    print(

    The value of (3**4) % 10 is : 1
    6(math.pow(1.0,x)8
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    0
    The value of (3**4) % 10 is : 1
    9math.pow(1.0,x)8
    The value of (3**4) % 10 is : 1
    8
    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625
    3

    Output:

    Positive x and positive y : 64
    Negative x and positive y : -64
    Positive x and negative y : 0.015625
    Negative x and negative y : -0.015625

    Làm thế nào để bạn sử dụng chức năng năng lượng trong Python?

    Cú pháp cho chức năng nguồn:..
    pow (x, y [, z]).
    Giá trị của 3 ** 4 là: 81 ..

    Làm thế nào để bạn tạo một chức năng năng lượng trong Python?

    Các chức năng sức mạnh khác trong Python..
    Sử dụng chức năng POW của gói toán học.Mã: Nhập cơ sở toán học = 2 Power = 5 In (Math. Pow (cơ sở, nguồn)) đầu ra:.
    Sử dụng chức năng năng lượng của gói numpy.Mã: Nhập Numpy dưới dạng NP Base = 2 Power = 5 In (NP. Power (cơ sở, nguồn)) đầu ra:.
    Sử dụng chức năng nguồn của gói SCIPY ..

    Làm thế nào để bạn thêm sức mạnh trong Python?

    Toán tử ** trong Python được sử dụng để tăng số ở bên trái lên sức mạnh của số mũ bên phải.Đó là, trong biểu thức 5 ** 3, 5 đang được nâng lên sức mạnh thứ 3.. That is, in the expression 5 ** 3 , 5 is being raised to the 3rd power.

    Pow () có nghĩa là gì trong Python?

    Hàm python pow () Hàm pow () trả về giá trị của x cho công suất của y (xy).Nếu có tham số thứ ba, nó sẽ trả lại x cho sức mạnh của y, mô đun z.returns the value of x to the power of y (xy). If a third parameter is present, it returns x to the power of y, modulus z.