1 Star 0 Fork 0

xinban/Python的内置函数

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
没有jk开头的内置函数么_l开头的有.py 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
xinban 提交于 2021-09-14 17:14 . test
'''
Python len() 方法返回对象(字符、列表、元组等)长度或项目个数。
len(n)
n -- 对象。
返回对象长度。
'''
str = "lidihuo"
a = len(str) # 字符串长度
print(a) # 7
print('-'*10,"分割线","-"*10)
'''
list() 方法用于将元组或字符串转换为列表。
注:元组与列表是非常类似的,区别在于元组的元素值不能修改,元组是放在括号中,列表是放于方括号中。
list( seq )
seq -- 要转换为列表的元组或字符串。
返回列表。
'''
tuple = (123, 'abc', 'lidihuo', 'baidu')
list1 = list(tuple)
print ("列表元素 : ", list1) # 列表元素 : [123, 'abc', 'lidihuo', 'baidu']
str = "Hello lidihuo"
list2 = list(str)
print ("列表元素 : ", list2) # 列表元素 : ['H', 'e', 'l', 'l', 'o', ' ', 'l', 'i', 'd', 'i', 'h', 'u', 'o']
print('-'*10,"分割线","-"*10)
'''
locals() 函数会以字典类型返回当前位置的全部局部变量。
对于函数, 方法, lambda 函式, 类, 以及实现了 __call__ 方法的类实例, 它都返回 True。
locals()
无参数
返回字典类型的局部变量。
'''
def lidihuo(arg): # 两个局部变量:arg、z
z = 1
print (locals())
# 返回一个名字/值对的字典
lidihuo(4) # {'z': 1, 'arg': 4}
print('-'*10,"分割线","-"*10)
'''
log() 方法返回x的自然对数,x > 0。
import math
math.log( x )
注意:log()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。
x -- 数值表达式。
返回x的自然对数,x>0。
'''
import math # 导入 math 模块
# 这里的log是以e作为对数的底数,x是对数的真数
print("math.log(2.7) : ", math.log(2.7)) # 0.9932517730102834
print("math.log(10.72) : ", math.log(10.72))
print("math.log(math.pi) : ", math.log(math.pi))
print('-'*10,"分割线","-"*10)
'''
log10() 方法返回以10为基数的x对数,x>0。
import math
math.log10( x )
注意:log10()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。
x -- 数值表达式。
返回以10为基数的x对数,x>0。
'''
#!/usr/bin/python3
import math # 导入 math 模块
print("math.log10(10) : ", math.log10(10)) # 1.0
print("math.log10(10.72) : ", math.log10(10.72))
print("math.log10(19) : ", math.log10(19))
print("math.log10(math.pi) : ", math.log10(math.pi))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qitu1024/built-in-functions-of-python.git
[email protected]:qitu1024/built-in-functions-of-python.git
qitu1024
built-in-functions-of-python
Python的内置函数
master

搜索帮助