Python Learning: string manipulation

Source: Internet
Author: User

1: Double quote escape

<span style= "FONT-SIZE:18PX;" ><strong>print "he\" Llo "</strong></span>
you only need to precede the double quotation mark with a backslash.

Output result: he "Llo


2: Concatenation of strings

(1) You can use the + number

<span style= "FONT-SIZE:18PX;" ><strong>print "Hello" + "" + "wolrd" </strong></span>

(2) You can use commas

<span style= "FONT-SIZE:18PX;" ><strong>print "Hello", "World" </strong></span>

(3) can use * number

<span style= "FONT-SIZE:18PX;" ><strong>print "Hello" *3</strong></span>

Output Result:

Hello wolrd
Hello World
Hellohellohello


3: String length

<span style= "FONT-SIZE:18PX;" ><strong>print len ("Hello") </strong></span>

Use the Len () function. Output Results 5


4: Type conversion: string to int

<span style= "FONT-SIZE:18PX;" ><strong>print Int ("111") + 1</strong></span>
Output Results


5: Type conversion: int to string

<span style= "FONT-SIZE:18PX;" ><strong>print "AAA" + str (1) </strong></span>

Using the function str

Output Result: AAA1




Python Learning: string manipulation

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.