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 -
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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
5 là
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
6,
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
7 là
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
8.
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 -100100>>>>>>abs(291.121)# absolute value of 291.121291.121>>>>>>abs(88)# absolute value of 8888>>>
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.
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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
5 là
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
6,
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
7 là
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.718>>>
8.
>>>>>>round(32.3)# round 32.3 to the nearest integer32>>>round(99.7)# round 99.7 to the nearest integer100>>>round(-5.23)# round -5.23 to the nearest integer-5>>>>>>round(3.14159,2)# round 3.14159 to 2 decimal places3.14>>>>>>round(2.71828,3)# round 2.71828 to 3 decimal places2.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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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 100100>>>>>>max(-21,4.5,91.12)# Find the largest among -21, 4.5 and 91.1291.12>>>>>>max(-67,-17,0)# Find the largest among -67, 417 and 00>>>>>>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:
Đâ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)
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ờ
>>>>>> 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 -100100>>>>>>abs(291.121)# absolute value of 291.121291.121>>>>>>abs(88)# absolute value of 8888>>>
0
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 ).