Python —— 不同类型的数据长度计算方式

在Python 中,不同类型的数据长度计算方式,有何不同👇

  • 字符串(String)
python 复制代码
my_string = "Hello, World!"
string_length = len(my_string)
print("字符串的长度是:", string_length)  //输出: 13
  • 数组(Array)
python 复制代码
my_list = [1, 2, 3, 4, 5]
list_length = len(my_list)
print("列表的长度是:", list_length) // 输出:5
  • 对象(Object)
python 复制代码
my_obj = {'a': 1, 'b': 2, 'c': 3}
obj_length = len(my_obj)
print("字典的键值对数量是:", obj_length) // 输出:3
  • 函数(Function)
python 复制代码
import inspect

def my_function(a, b, c):
    return a + b + c

function_length = len(inspect.signature(my_function).parameters)
print("函数的参数数量是:", function_length) // 输出:3
相关推荐
徐先生 @_@|||25 分钟前
Palantir Foundry 五层架构模型详解
开发语言·python·深度学习·算法·机器学习·架构
深蓝电商API1 小时前
Scrapy爬虫限速与并发控制最佳实践
爬虫·python·scrapy
Derrick__11 小时前
淘宝MD5爬虫
爬虫·python
薛定谔的猫19821 小时前
llama-index Embedding 落地到 RAG 系统
开发语言·人工智能·python·llama-index
nimadan123 小时前
**手机小说扫榜工具2025推荐,精准追踪榜单动态与题材风向
python·智能手机
编程武士3 小时前
Python 各版本主要变化速览
开发语言·python
傻啦嘿哟3 小时前
Python中的@property:优雅控制类成员访问的魔法
前端·数据库·python
sky17204 小时前
VectorStoreRetriever 三种搜索类型
python·langchain
旦莫4 小时前
Python测试开发工具库:日志脱敏工具(敏感信息自动屏蔽)
python·测试开发·自动化·ai测试
唐叔在学习4 小时前
Python自动化指令进阶:UAC提权
后端·python