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

Source: Internet
Author: User
function: Len ()

1: Function: Returns the length of 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 strings, lists, dictionaries, tuples, and so on

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

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


5.2. Count the number of elements in 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-value pairs):

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


5.4, calculate the number of tuple elements:

>>> t = (' G ', ' o ', ' o ', ' d ') >>> Len (t) 4
  • 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.