A brief introduction to the use of len () functions in Python-Python tutorial

Source: Internet
Author: User
This article briefly introduces the use of len () functions in Python, including the use of small examples in four cases, which is the basic knowledge in Python learning, for more information, see len ()

1: role:Returns the string, list, dictionary, and tuples.

2: syntax:Len (str)

3: parameters:
Str: string, list, dictionary, and tuples to be calculated

4: return value: Length of strings, lists, dictionaries, tuples, and other elements

5: instance
5.1. calculate the length of the string:

>>> S = "hello good boy doiido" >>> len (s) 21


5.2. number of elements in the computing 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 tuples:

>>> 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.