GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.runoob.com — Python3 len()方法 | 菜鸟教程
Python 3 教程
Python3 教程
Python3 简介
Python3 环境搭建
Python3 Pycharm
Python3 VScode
Python3 基础语法
Python3 基本数据类型
Python3 数据类型转换
Python3 解释器
Python3 注释
Python3 运算符
Python3 数字(Number)
Python3 字符串
Python3 列表
Python3 元组
Python3 字典
Python3 集合
Python3 条件控制
Python3 循环语句
Python3 编程第一步
Python3 推导式
Python3 迭代器与生成器
Python3 with
Python3 函数
Python3 lambda
Python3 装饰器
Python3 数据结构
Python3 模块
Python __name__
Python3 输入和输出
Python3 File
Python3 OS
Python3 错误和异常
Python3 面向对象
Python3 命名空间/作用域
Python 虚拟环境的创建
Python 类型注解
Python3 标准库概览
Python3 实例
Python 测验
Python3 高级教程Python3 正则表达式 Python3 CGI编程 Python3 MySQL(mysql-connector) Python3 MySQL(PyMySQL) Python3 网络编程 Python3 SMTP发送邮件 Python3 多线程 Python3 XML 解析 Python3 JSON Python3 日期和时间 Python3 内置函数 Python3 MongoDB Python3 urllib Python uWSGI 安装配置 Python3 pip Python3 operator Python math Python requests Python random Python OpenAI Python 有用的资源 Python AI 绘画 Python statistics Python hashlib Python 量化 Python pyecharts Python selenium 库 Python 爬虫 Python Scrapy 库 Python Markdown Python sys 模块 Python Pickle 模块 Python subprocess 模块 Python queue 模块 Python StringIO 模块 Python logging 模块 Python datetime 模块 Python re 模块 Python csv 模块 Python threading 模块 Python asyncio 模块 Python PyQtPython3 len()方法描述Python len() 是 Python 内置函数,用于返回对象的长度或元素个数,适用于字符串、列表、元组等具有长度信息的数据类型。 len() 也适用于其他可迭代对象,如集合等。 语法len()方法语法: len( s ) 参数
返回值返回对象长度。 实例以下实例展示了 len() 的使用方法: 字符串的长度: 实例text = "Hello, World!"
length = len(text)
print(length) # 输出:13 以上实例中,len(text) 返回字符串 text 的字符数,包括空格和标点符号,输出结果为: 13 列表的长度: 实例my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print(length) # 输出:5 以上实例中,len(my_list) 返回列表 my_list 中的元素数量,输出结果为: 5 元组的长度: 实例my_tuple = (10, 20, 30)
length = len(my_tuple)
print(length) # 输出:3 以上实例中,len(my_tuple) 返回元组 my_tuple 中的元素数量,输出结果为: 3 集合的长度: 实例my_set = {5, 10, 15, 20}
length = len(my_set)
print(length) # 输出:4 以上实例中,len(my_set) 返回集合 my_set 中的唯一元素数量,输出结果为: 4 字典的长度: 实例my_dict = {"apple": 3, "banana": 2, "cherry": 4}
length = len(my_dict)
print(length) # 输出:3 以上实例中,len(my_dict) 返回字典 my_dict 中键-值对的数量,输出结果为: 3 总之,len() 函数是一个非常实用的工具,用于确定各种类型的序列的长度,这对于编写各种 Python 程序非常有用。 注意事项
AI 思考中...
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |