Hướng dẫn how do you express an exponential form in python? - làm thế nào để bạn thể hiện một dạng hàm mũ trong python?



Sự mô tả

Phương thức số Python exp () Trả về Trả về hàm mũ của x: ex.exp() returns returns exponential of x: ex.

Show

Cú pháp

Sau đây là Phương thức Cú pháp cho Exp () -exp() method −

import math

math.exp( x )

Lưu ý - Hàm này không thể truy cập trực tiếp, vì vậy chúng ta cần nhập mô -đun toán học và sau đó chúng ta cần gọi hàm này bằng đối tượng Static Math. − This function is not accessible directly, so we need to import math module and then we need to call this function using math static object.

Thông số

  • x - Đây là một biểu thức số. − This is a numeric expression.

Giá trị trả về

Phương pháp này trả về hàm mũ của x: Ex.

Thí dụ

Ví dụ sau đây cho thấy phương thức sử dụng exp ().

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)

Khi chúng tôi chạy trên chương trình, nó tạo ra kết quả sau -

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328

python_numbers.htm

  1. Nhà
  2. Hướng dẫn Python
  3. Số trong Python

Cập nhật lần cuối vào ngày 17 tháng 9 năm 2020


Số trong Python #

Trong Python, các số có 4 loại:

  1. Integer.
  2. Điểm nổi hoặc số thực.
  3. Số phức.
  4. Boolean.

Các số nguyên hoặc

>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
1 là những con số không có dấu thập phân. Ví dụ:
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
2,
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
3,
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
4 là
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
1 nhưng
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
6,
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
7,
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
8 thì không.

Điểm nổi hoặc thực hoặc

>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
9 là những con số có dấu thập phân. Ví dụ,
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
0,
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
1,
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
2 là nổi nhưng
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
3,
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
4 thì không. Chúng ta cũng có thể viết số điểm nổi bằng cách sử dụng ký hiệu khoa học. Các số được viết ở dạng
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
5 được gọi là ký hiệu khoa học. Ký hiệu khoa học là khá hữu ích để viết số rất nhỏ hoặc rất lớn. Ví dụ, float
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
6 có thể được viết ngắn gọn trong ký hiệu khoa học là
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
7. Python sử dụng một cú pháp đặc biệt để viết số trong ký hiệu khoa học. Ví dụ,
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
6 có thể được viết là
>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>
9. Chữ
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
0 được gọi là số mũ và không quan trọng bạn sử dụng
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
1 hay
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
0.

Các số phức là các số mà chúng ta không thể biểu diễn trên một dòng số. Một số phức tạp có dạng

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
3, trong đó
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
4 là phần thực và
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
5 là phần tưởng tượng. Ví dụ,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
6 là số phức. Python cũng sử dụng một cú pháp đặc biệt cho các số phức. Một số nguyên hoặc float với dấu vết
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
7 được coi là một số phức trong Python, do đó
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
8,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
9 là các số phức tạp.

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>

Thử ngay bây giờ

Lưu ý rằng

>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
0 chỉ đại diện cho phần tưởng tượng của số phức. Để tạo một số phức tạp với phần thực và tưởng tượng, chỉ cần thêm một số vào phần tưởng tượng. Ví dụ, số phức
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
6 có thể được viết bằng Python là
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
2.

Loại Boolean được thảo luận sau trong chương này.

Các chức năng toán học phổ biến #

Python cung cấp chức năng tích hợp sau để giúp bạn hoàn thành các nhiệm vụ lập trình chung:

Hàm sốNhững gì nó làm ?Thí dụ
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
3
Trả về giá trị tuyệt đối của số. Nói cách khác, hàm
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
4 chỉ trả về số mà không có bất kỳ dấu hiệu nào.
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
5 là
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
6,
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
7 là
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
8.
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
9
Trả về
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
0.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
1 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
2,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
3 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
4
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
5
Làm tròn số vào số nguyên gần nhất.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
6 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
7,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
8 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
9
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
0
Vòng tròn
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
1 đến
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
2 sau dấu thập phân
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
3 là
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
4,
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
5 là
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
6
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
7
Trả về mặt hàng nhỏ nhất trong số
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
8,
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
9, ...
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
00
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
01 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
02,
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
03 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
04
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
05
Trả về mục lớn nhất trong số
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
8,
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
9, ...
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
00
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
09 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
10,
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
11 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
12

hàm abs () #

>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>

Thử ngay bây giờ

Lưu ý rằng >>> >>> round(32.3) # round 32.3 to the nearest integer 32 >>> round(99.7) # round 99.7 to the nearest integer 100 >>> round(-5.23) # round -5.23 to the nearest integer -5 >>> >>> round(3.14159, 2) # round 3.14159 to 2 decimal places 3.14 >>> >>> round(2.71828, 3) # round 2.71828 to 3 decimal places 2.718 >>> 0 chỉ đại diện cho phần tưởng tượng của số phức. Để tạo một số phức tạp với phần thực và tưởng tượng, chỉ cần thêm một số vào phần tưởng tượng. Ví dụ, số phức 1 2 3 4 5 6 7 8 9 10 11 12 13 146 có thể được viết bằng Python là >>> >>> round(32.3) # round 32.3 to the nearest integer 32 >>> round(99.7) # round 99.7 to the nearest integer 100 >>> round(-5.23) # round -5.23 to the nearest integer -5 >>> >>> round(3.14159, 2) # round 3.14159 to 2 decimal places 3.14 >>> >>> round(2.71828, 3) # round 2.71828 to 3 decimal places 2.718 >>> 2.

>>>
>>> pow(3, 3)           # calculate 3^3
27
>>>
>>> pow(0.35, 2)        # calculate 0.35^2
0.12249999999999998
>>>
>>> pow(9, -2)          # calculate 9^-2
0.012345679012345678
>>>

Thử ngay bây giờ

Lưu ý rằng >>> >>> round(32.3) # round 32.3 to the nearest integer 32 >>> round(99.7) # round 99.7 to the nearest integer 100 >>> round(-5.23) # round -5.23 to the nearest integer -5 >>> >>> round(3.14159, 2) # round 3.14159 to 2 decimal places 3.14 >>> >>> round(2.71828, 3) # round 2.71828 to 3 decimal places 2.718 >>> 0 chỉ đại diện cho phần tưởng tượng của số phức. Để tạo một số phức tạp với phần thực và tưởng tượng, chỉ cần thêm một số vào phần tưởng tượng. Ví dụ, số phức 1 2 3 4 5 6 7 8 9 10 11 12 13 146 có thể được viết bằng Python là >>> >>> round(32.3) # round 32.3 to the nearest integer 32 >>> round(99.7) # round 99.7 to the nearest integer 100 >>> round(-5.23) # round -5.23 to the nearest integer -5 >>> >>> round(3.14159, 2) # round 3.14159 to 2 decimal places 3.14 >>> >>> round(2.71828, 3) # round 2.71828 to 3 decimal places 2.718 >>> 2.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14

>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>

Thử ngay bây giờ

Lưu ý rằng >>> >>> round(32.3) # round 32.3 to the nearest integer 32 >>> round(99.7) # round 99.7 to the nearest integer 100 >>> round(-5.23) # round -5.23 to the nearest integer -5 >>> >>> round(3.14159, 2) # round 3.14159 to 2 decimal places 3.14 >>> >>> round(2.71828, 3) # round 2.71828 to 3 decimal places 2.718 >>> 0 chỉ đại diện cho phần tưởng tượng của số phức. Để tạo một số phức tạp với phần thực và tưởng tượng, chỉ cần thêm một số vào phần tưởng tượng. Ví dụ, số phức 1 2 3 4 5 6 7 8 9 10 11 12 13 146 có thể được viết bằng Python là >>> >>> round(32.3) # round 32.3 to the nearest integer 32 >>> round(99.7) # round 99.7 to the nearest integer 100 >>> round(-5.23) # round -5.23 to the nearest integer -5 >>> >>> round(3.14159, 2) # round 3.14159 to 2 decimal places 3.14 >>> >>> round(2.71828, 3) # round 2.71828 to 3 decimal places 2.718 >>> 2.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17

>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>

Thử ngay bây giờ

Lưu ý rằng

>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
0 chỉ đại diện cho phần tưởng tượng của số phức. Để tạo một số phức tạp với phần thực và tưởng tượng, chỉ cần thêm một số vào phần tưởng tượng. Ví dụ, số phức
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
6 có thể được viết bằng Python là
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
2.

Loại Boolean được thảo luận sau trong chương này.

Hàm sốNhững gì nó làm ?Thí dụ
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
3
Trả về giá trị tuyệt đối của số. Nói cách khác, hàm
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
4 chỉ trả về số mà không có bất kỳ dấu hiệu nào.
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
5 là
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
6,
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
7 là
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
8.
>>>
>>> round(32.3)         # round 32.3 to the nearest integer
32
>>> round(99.7)         # round 99.7 to the nearest integer
100
>>> round(-5.23)        # round -5.23 to the nearest integer
-5
>>>
>>> round(3.14159, 2)   # round 3.14159 to 2 decimal places
3.14
>>>
>>> round(2.71828, 3)   # round 2.71828 to 3 decimal places
2.718
>>>
9
Trả về
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
0.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
1 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
2,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
3 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
4
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
5
Làm tròn số vào số nguyên gần nhất.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
6 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
7,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
8 là
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
9
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
0
Vòng tròn
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
1 đến
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
2 sau dấu thập phân
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
3 là
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
4,
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
5 là
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
6
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
7
Trả về mặt hàng nhỏ nhất trong số
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
8,
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
9, ...
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
00
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
01 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
02,
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
03 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
04
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
05
Trả về mục lớn nhất trong số
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
8,
>>>
>>> max(1, 4, 100)      # Find the largest among 1, 4 and 100
100
>>>
>>> max(-21, 4.5, 91.12)   # Find the largest among -21, 4.5 and 91.12
91.12
>>>
>>> max(-67, -17, 0)        # Find the largest among -67, 417 and 0
0
>>>
>>> min(0, -1.23e10, -9921)  # Find the smallest among 0, -1.23e10 and -9921
-12300000000.0
>>>
>>>
>>> min(92, 6, -102)     # Find the largest among 92, 6, -102
-102
>>>
9, ...
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
00
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
09 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
10,
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
11 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
12
hàm abs () #hàm pow () #chức năng vòng () #
hàm tối đa () và min () #Mô -đun
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
13 của Python cũng cung cấp một số hàm và hằng số toán học tiêu chuẩn. Hãy nhớ lại rằng, để sử dụng mô -đun toán học, trước tiên chúng ta cần nhập nó bằng câu lệnh
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
14 như sau:
Bảng sau liệt kê một số hàm và hằng số tiêu chuẩn trong mô -đun
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
13.
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
16
Trả về giá trị của
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
17
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
16 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
19
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
20
Trả về giá trị của
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
1
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
20 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
23
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
24
Trả về số nguyên nhỏ nhất lớn hơn hoặc bằng
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
25
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
26 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
27
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
28
Trả về số nguyên lớn nhất nhỏ hơn hoặc bằng
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
25
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
62 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
63
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
64
Chuyển đổi góc từ độ thành radian
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
65 là
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
66

Thử ngay bây giờ

Math.pi và math.e hằng số #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
0

Math.ceil () và Math.Floor () hàm #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
1

Math.fabs () và math.sqrt () hàm #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
2

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
3

hàm math.log () #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
4

Math.sin (), Math.cos () và Math.tan () hàm #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
5

Chức năng Math.Degrees () và Math.Radians () #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
6

Đây chỉ là một hàm danh sách ngắn và hằng số trong mô -đun toán học, để xem danh sách đầy đủ, hãy truy cập https://docs.python.org/dev/l Library/math.html.

Định dạng số #

Đôi khi nó là mong muốn để in số theo một định dạng cụ thể. Xem xét ví dụ sau:

python101/Chapter-05/simple_interest_calculator.py

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
7

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
8

Output:

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
9

Thử ngay bây giờ

Math.pi và math.e hằng số #

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
0

Math.ceil () và Math.Floor () hàm #

python101/Chapter-05/simple_interest_calculator_using_format_function.py

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
7

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
2

Output:

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
3

Thử ngay bây giờ

Math.pi và math.e hằng số #

Math.ceil () và Math.Floor () hàm #

Math.fabs () và math.sqrt () hàm #

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
4

hàm math.log () #

Math.sin (), Math.cos () và Math.tan () hàm #

Chức năng Math.Degrees () và Math.Radians () #

Đây chỉ là một hàm danh sách ngắn và hằng số trong mô -đun toán học, để xem danh sách đầy đủ, hãy truy cập https://docs.python.org/dev/l Library/math.html.

Định dạng số #

Đôi khi nó là mong muốn để in số theo một định dạng cụ thể. Xem xét ví dụ sau:

Lưu ý cách số tiền được hiển thị trong đầu ra, nó chứa

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
67 chữ số sau thập phân. Đây là vấn đề rất phổ biến khi số điểm nổi được in sau khi thực hiện các tính toán. Vì số tiền là tiền tệ, nên định dạng nó thành hai vị trí thập phân. Chúng ta có thể dễ dàng làm tròn số đến 2 số thập phân bằng cách sử dụng hàm
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
68, nhưng hàm
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
68 sẽ không luôn luôn đưa ra câu trả lời chính xác. Xem xét mã sau:

Chúng tôi muốn xuất ra

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
70 không phải
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
71. Chúng ta có thể khắc phục sự cố này bằng cách sử dụng hàm
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
72. Dưới đây là phiên bản sửa đổi của chương trình trên bằng phương pháp
#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
72.

Hàm

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
72 được giải thích trong phần tiếp theo.:

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
5

Thử ngay bây giờ

Hướng dẫn how do you express an exponential form in python? - làm thế nào để bạn thể hiện một dạng hàm mũ trong python?

Math.pi và math.e hằng số #

Math.ceil () và Math.Floor () hàm #:

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
6

Thử ngay bây giờ

Hướng dẫn how do you express an exponential form in python? - làm thế nào để bạn thể hiện một dạng hàm mũ trong python?

Math.pi và math.e hằng số #

Math.ceil () và Math.Floor () hàm #

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
7

Thử ngay bây giờ

Math.pi và math.e hằng số #

Math.ceil () và Math.Floor () hàm #

Math.fabs () và math.sqrt () hàm #

#!/usr/bin/python
import math   # This will import math module

print "math.exp(-45.17) : ", math.exp(-45.17)
print "math.exp(100.12) : ", math.exp(100.12)
print "math.exp(100.72) : ", math.exp(100.72)
print "math.exp(119L) : ", math.exp(119L)
print "math.exp(math.pi) : ", math.exp(math.pi)
2

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
9

Thử ngay bây giờ

Math.pi và math.e hằng số #

Math.ceil () và Math.Floor () hàm #

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
0

Thử ngay bây giờ

Math.fabs () và math.sqrt () hàm #

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
1

Định dạng số dưới dạng tỷ lệ phần trăm #

Chúng ta có thể sử dụng mã loại

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
05 để định dạng một số theo tỷ lệ phần trăm. Khi
math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
05 được sử dụng trong bộ đặc điểm định dạng, nó sẽ nhân số lượng với
>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
2 và đưa ra kết quả dưới dạng phao theo sau là dấu
math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
05. Chúng tôi cũng có thể chỉ định chiều rộng và độ chính xác như bình thường.

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
2

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
3

Thử ngay bây giờ

Cài đặt căn chỉnh #

Chúng tôi đã thảo luận rằng theo mặc định, các số được in đúng. Ví dụ:

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
4

Thử ngay bây giờ

Cài đặt căn chỉnh #

Chúng tôi đã thảo luận rằng theo mặc định, các số được in đúng. Ví dụ:Chúng ta có thể thay đổi căn chỉnh mặc định bằng cách sử dụng hai ký hiệu sau:
Biểu tượngSự mô tả
math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
09
Đầu ra giá trị đúng biện minh trong chiều rộng được chỉ định

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
10

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
5

Đầu ra, giá trị còn lại hợp lý trong chiều rộng được chỉ định

Hướng dẫn how do you express an exponential form in python? - làm thế nào để bạn thể hiện một dạng hàm mũ trong python?

Biểu tượng căn chỉnh phải đến trước chiều rộng được chỉ định.

Ở đây chúng tôi đang in số còn lại chính đáng, do kết quả không gian kéo dài được thêm vào thay vì không gian hàng đầu.

Lưu ý rằng câu lệnh

math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
11 và
math.exp(-45.17) :  2.41500621326e-20
math.exp(100.12) :  3.03084361407e+43
math.exp(100.72) :  5.52255713025e+43
math.exp(119L) :  4.7978133273e+51
math.exp(math.pi) :  23.1406926328
12 giống như đúng là định dạng mặc định cho các số in.

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
6

Thử ngay bây giờ

Hướng dẫn how do you express an exponential form in python? - làm thế nào để bạn thể hiện một dạng hàm mũ trong python?

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
7

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
8

>>>
>>> type(5)   # an integer
<class 'int'>
>>>
>>> type(3.4)  # a float
<class 'float'>
>>>
>>> type(5j)  # a complex number
<class 'complex'>
>>>
9

>>>
>>> abs(-100)      # absolute value of -100
100
>>>
>>> abs(291.121)   # absolute value of 291.121
291.121
>>>
>>> abs(88)        # absolute value of 88
88
>>>
0

Hướng dẫn how do you express an exponential form in python? - làm thế nào để bạn thể hiện một dạng hàm mũ trong python?



Cài đặt căn chỉnh #

Toán tử số mũ (**) Chúng tôi sử dụng toán tử ASTERISK/ASTERIATION (**) (**) (**) giữa các giá trị cơ sở và số mũ.Trong ví dụ trên, chúng tôi đã lấy cơ sở 2 và số mũ là 16. Ở đây, 2 được nhân 16 lần.Đây là phương pháp đơn giản nhất để tính toán giá trị theo cấp số nhân trong Python.use the (**) double asterisk/exponentiation operator between the base and exponent values. In the above example, we took base 2 and exponent as 16. Here, 2 gets multiplied 16 times. It is the simplest method for calculating the exponential value in Python.

Biểu tượng Python cho số mũ là gì?

Toán tử POWER (số mũ) Toán tử có thể được sử dụng để thực hiện số học số mũ trong Python là **.Với hai toán hạng số thực, một ở mỗi bên của toán tử, nó thực hiện tính toán theo cấp số nhân (2 ** 5 dịch thành 2*2*2*2*2).** . Given two real number operands, one on each side of the operator, it performs the exponential calculation ( 2**5 translates to 2*2*2*2*2 ).