龙空技术网

DAY3-step8 Python字符串长度 len方法

易小盟办公设备企业店 79

前言:

目前兄弟们对“pythonlen字符串长度怎么算”大概比较珍视,我们都需要剖析一些“pythonlen字符串长度怎么算”的相关资讯。那么小编也在网上收集了一些对于“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

标签: #pythonlen字符串长度怎么算