最近有很多读者朋友在python中len()用法有疑问。有网友整理了相关内容,希望能回答你的疑惑,关于pythonlen本网站还为您找到了问题的答案,希望能对您有所帮助。
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 listlist1=["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 tupleTup=('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 DictionaryDict={'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 arrayarr1=['Tim','Charlie','Tiffany','Robert']print("The length of the Array is", len(arr1))
输出
The length of the Array is 4
主题测试文章,只做测试使用。发布者:艾迪号,转转请注明出处:https://www.cqaedi.cn/baike/46957.html