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
相关推荐
Esaka_Forever14 小时前
Python 完整内存管理机制详解
开发语言·python·spring
Weigang15 小时前
用 LlamaIndex 做 RAG 前,先把 Reader、Index、Retriever 的边界写清楚
人工智能·python·开源
小九九的爸爸15 小时前
前端入门Agent开发,掌握这些Python数据基础就够啦
python·agent
风之所往_15 小时前
Python 3.9 新特性全面总结
python
W是笔名15 小时前
python___容器类型的数据___序列
开发语言·python
aqi0015 小时前
15天学会AI应用开发(十一)从TXT文件构建RAG知识库
人工智能·python·大模型·ai编程·ai应用
火星校尉15 小时前
一场数据基建与消费场景的跨界实验
java·前端·数据库·python·php
Sam092715 小时前
【AI 算法精讲 14】TF-IDF:词频与逆文档频率
人工智能·python·算法·ai
W是笔名15 小时前
python_let`s try it 6___BMI计算器
java·前端·python