python--about connectors +

Source: Internet
Author: User

Connector +

Connector + actually creates a new object and consumes new memory (DICT, set cannot be used)

String

Because Python must allocate new memory for each string that uses the connector +, and produce a new string. The following two ways are more effective

① using the format operator (%)

>>> '%s%s '% (' hello ', ' world ')

' Hello World '
>>>

   ② the string into the list, using the join connection

>>> ' _ '. Join ([' Hello ', ' world ')

' Hello_world '
>>>

List

Ibid., two lists using + Connect is the generation of a new list. can be list.extend () instead of +

>>> p = [+ +]

    >>> pp = [4,5,6]
>>> p.extend (PP)
>>> P
[1, 2, 3, 4, 5, 6]
>>>

python--about connectors +

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.