A brief introduction to the use of the Len () function in Python _python

Source: Internet
Author: User
Tags in python

function: Len ()

1: Function: Returns the length of a string, list, dictionary, tuple, etc.

2: Syntax:len (str)

3: Parameters:
str: string, list, dictionary, tuple, etc. to be computed

4: Return value : Length of elements such as String, list, dictionary, tuple, etc.

5: Example
5.1, the length of the calculation string:

>>> s = "Hello good boy doiido"
>>> Len (s)
21


5.2, calculate the number of elements of the list:

>>> L = [' h ', ' e ', ' l ', ' l ', ' o ']
>>> len (l)
5


5.3, calculate the total length of the dictionary (that is, the total number of key values):

>>> d = {' num ': 123, ' name ': ' Doiido '}
>>> len (d)
2


5.4. Calculate the number of tuple elements:

>>> t = (' G ', ' o ', ' o ', ' d ')
>>> len (t)
4

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.