How to express logarithmic function in python

爱喝马黛茶的安东尼
Release: 2019-06-24 16:26:46
Original
32695 people have browsed it

log() returns the natural logarithm of x. math.log(x) is equivalent to ln(x) in mathematics, x>0, find the logarithm with the base e, e = 2.718281828459; math.log10(x) is equivalent to lg(x) in mathematics, x>0, find the logarithm with base 10. The base can be set by log(x[, base]), for example, log(x, 10) represents the logarithm with base 10.

How to express logarithmic function in python

Syntax

The following is the syntax of the log() method:

import math
math.log(x[, base])
Copy after login

Note: log() is If it cannot be accessed directly, you need to import the math module and call this method through a static object.

Parameters

x -- Numeric expression. base -- optional, base, default is e.

Related recommendations: "Python Video Tutorial"

Return value

Returns the natural logarithm of x, x>0 .

Example

The following shows an example of using the log() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import math   # 导入 math 模块
print "math.log(100.12) : ", math.log(100.12)
print "math.log(100.72) : ", math.log(100.72)
print "math.log(119L) : ", math.log(119L)
print "math.log(math.pi) : ", math.log(math.pi)# 设置底数
print "math.log(10,2) : ", math.log(10,2)
Copy after login

The output result after running the above example is:

math.log(100.12) :  4.60636946656
math.log(100.72) :  4.61234438974
math.log(119L) :  4.77912349311
math.log(math.pi) :  1.14472988585
math.log(10,2) :  3.32192809489
Copy after login

The above is the detailed content of How to express logarithmic function in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!