网站首页 > 技术文章 正文
len()是python中的内置函数。 您可以使用len()获得给定字符串,数组,列表,元组,字典等的长度。
语法:
len(value)
参数:
value:您想要的长度的给定值。
返回值
将返回一个整数值,即给定的字符串,数组,列表或集合的长度。
示例1:如何找到给定字符串的长度?
# testing len()
str1 = "Welcome to Guru99 Python Tutorials"
print("The length of the string is :", len(str1))
输出
The length of the string is : 35
示例2:如何在python中查找列表的长度?
# to find the length of the list
list1 = ["Tim","Charlie","Tiffany","Robert"]
print("The length of the list is", len(list1))
输出
The length of the list is 4
示例3:如何在python中查找元组的长度
# to find the length of the tuple
Tup = ('Jan','feb','march')
print("The length of the tuple is", len(Tup))
输出
The length of the tuple is 3
示例4:如何在Python中查找字典的长度?
# to find the length of the Dictionary
Dict = {'Tim': 18,'Charlie':12,'Tiffany':22,'Robert':25}
print("The length of the Dictionary is", len(Dict))
输出
The length of the Dictionary is 4
示例5:如何在python中查找数组的长度
# to find the length of the array
arr1 = ['Tim','Charlie','Tiffany','Robert']
print("The length of the Array is", len(arr1))
输出
The length of the Array is 4
猜你喜欢
- 2024-11-20 Python基础编程——算术运算
- 2024-11-20 Python字符串方法之-字符串填充
- 2024-11-20 Python第14题:最长公共前缀【leetcode】
- 2024-11-20 从 0 到 1:构建强大且易用的规则引擎
- 2024-11-20 分享3个干货满满的Python实战项目,点赞收藏
- 2024-11-20 python笔记8:静静一起来学习-字符串相关方法
- 2024-11-20 零基础Python完全自学教程14:Python中的序列知识详解
- 2024-11-20 你需要了解的最重要的Python概念
- 2024-11-20 Python整数缓存机制
- 2024-11-20 老鸟进阶必备技能,看懂显示器参数
- 最近发表
-
- 用Cursor开启JAVA+AI生涯_javascirpt怎么开启
- 大数据调度服务监控平台_大数据调度是什么意思
- SpringBoot、MyBatis、Vue搭建一个Java企业应用开源框架源码分享
- 大数据技术之Flume_大数据volume的含义
- Jenkins运维之路(Slave容器节点)_jenkins slave工作原理
- 程序员自救指南:IDEA 卡成狗?我的 9G 堆内存调参表让你起飞 附避坑
- JMeter:一个简单的测试计划怎么做?
- Windows 命令行终端 PowerShell 美化计划
- JDK25即将发布!新特性概览_jdk52.0
- JDK 25 新特性极简总结(2025 年 9 月 16 日发布,LTS 长期支持)
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- c语言min函数头文件 (77)
- asynccallback (87)
- localstorage.removeitem (77)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 无效的列索引 (74)