Python API len函数操作过程解析
作者:猿说python 时间:2021-01-29 01:15:29
在python中除了print函数之外,len函数和type函数应该算是使用最频繁的API了,操作都比较简单。
一.len函数简介
返回对象的长度(项目数)参数可以是序列(例如字符串str、元组tuple、列表list)或集合(例如字典dict、集合set或冻结集合frozenset)
语法:
len(s)
参数:
s – 对象或者序列(例如字符串str、元组tuple、列表list)或集合(例如字典dict、集合set或冻结集合)
返回值:返回长度(>=0)
二.len函数使用
# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:何以解忧
@Blog(个人博客地址): shuopython.com
@WeChat Official Account(微信公众号):猿说python
@Github:www.github.com
@File:python_len.py
@Time:2020/1/16 21:25
@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
"""
a = (1,2,3,4,5,6) #元组
b = [1,2,3,4] #列表
c = range(0,11) #range
d = {'name':'lisi','age':14} #字典
e = 'helloworld' #字符串
f = {1,2,3,4,5} #集合
g = frozenset([1,2,3,4,5,8]) #冻结集合
print("a:",len(a))
print("b:",len(b))
print("c:",len(c))
print("d:",len(d))
print("e:",len(e))
print("f:",len(f))
输出结果:
a: 6
b: 4
c: 11
d: 2
e: 10
f: 5
来源:https://www.cnblogs.com/shuopython/p/12364746.html
标签:python,len,函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP实现最简洁的多重查询的解决方案
2007-09-28 12:00:00
python中itertools模块使用小结
2023-08-07 18:44:32
用CSS实现柱状图(Bar Graph)的方法(四)—table实现复杂柱状图
2008-05-28 12:55:00
![](https://img.aspxhome.com/file/UploadPic/20085/28/200852813283924s.jpg)
分类、属性、关键词与Tag
2009-08-27 12:57:00
python 怎样进行内存管理
2021-04-27 16:46:18
TensorFlow变量管理详解
2023-11-23 07:11:18
![](https://img.aspxhome.com/file/2023/4/107204_0s.jpg)
PHP脚本监控Nginx 502错误并自动重启php-fpm
2023-09-26 00:11:45
详解Python中位运算的简单实现
2021-09-07 14:36:38
教程:纯CSS作的小灯笼效果
2008-08-26 17:22:00
![](https://img.aspxhome.com/file/UploadPic/20088/26/2008826173212465s.gif)
Python快速实现一键抠图功能的全过程
2021-03-03 14:58:39
![](https://img.aspxhome.com/file/2023/6/66926_0s.png)
Python条件语句的使用
2023-01-04 04:03:36
![](https://img.aspxhome.com/file/2023/4/101284_0s.png)
如果用JS得到字符串中出现次数最多的字母
2007-12-03 21:01:00
pyinstaller打包遇到的问题解决
2021-07-22 07:56:24
![](https://img.aspxhome.com/file/2023/3/101433_0s.jpg)
判断字段是否被更新 新旧数据写入Audit Log表中
2012-01-29 17:56:33
Python列表推导式、字典推导式与集合推导式用法实例分析
2022-04-10 10:34:00
Python函数装饰器实现方法详解
2023-08-10 12:33:16
php实现搜索一维数组元素并删除二维数组对应元素的方法
2023-10-09 05:45:40
python多线程用法实例详解
2023-02-08 11:24:03
Python input输入超时选择默认值自动跳过问题
2023-02-22 07:22:40
![](https://img.aspxhome.com/file/2023/5/112995_0s.png)
网页栅格系统研究(3):粒度问题
2008-10-28 19:46:00
![](https://img.aspxhome.com/file/UploadPic/200810/28/2008102819524130s.png)