Python len函数 - Python零基础入门教程
生活随笔
收集整理的這篇文章主要介紹了
Python len函数 - Python零基础入门教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 一.Python len 函數簡介
- 二.Python len 函數使用
- 三.猜你喜歡
零基礎 Python 學習路線推薦 : Python 學習目錄 >> Python 基礎入門
在 Python 中除了 print 函數之外,len 函數和 type 函數應該算是使用最頻繁的 API 了,操作都比較簡單。
一.Python len 函數簡介
返回對象的長度(項目數)參數可以是序列(例如**字符串 str** 、元組 tuple 、列表 list )或集合(例如**字典 dict** 、集合 set 或凍結集合 frozenset ),語法如下:
''' 參數:s – 對象或者序列(例如字符串str、元組tuple、列表list)或集合(例如字典dict、集合set或凍結集合)返回值:返回長度(>=0) '''len(s)二.Python len 函數使用
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python len 函數.py @Time:2021/04/29 07:37 @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 ’‘’三.猜你喜歡
未經允許不得轉載:猿說編程 ? Python len 函數
總結
以上是生活随笔為你收集整理的Python len函数 - Python零基础入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React之类式组件中的构造器与prop
- 下一篇: Python enumerate 函数