Python connector types and usage differences

Source: Internet
Author: User

Python's connectors are mainly the plus (+), comma (,), space (), backslash (\), join (),

Plus (+), the demo is as follows:

#注意, + can only concatenate strings, if one is a string one is a number will be error print "Here is the string" + "Here is also the string" #另外, here the string can also be a variable form, as follows DEMO:STR = "Here is the string" print "Here is the string" + str

Comma (,), the demo is as follows:

s = ' Here is the string ' #逗号可以连接字符串或数字, but the connection is displayed with a space print "character length:", Len (s)         #可以连接, but the display ' here is String 66666666 ' in the middle there is a space print " Here is the string ", 66666666     

  

Space (), demo as follows:

#字符串之间什么也不加, it's also possible. But if the string is a variable form, it will not be an error, only with +print "here is the string" "Here is also the string"

  

backslash (\), demo is as follows:

# Just the string is too long to wrap, to distinguish between three single quotes and three double quotation marks of the difference # In addition, before and after the connection can only be a string, not the variable print "Here is the string"       "Here is the string 2"

  

Join () method does not cite examples, other ways to continue to add later

Python connector types and usage differences

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.