Python Learning Notes String __python

Source: Internet
Author: User

The relevant use of strings 1, the definition of a string (single and double quotes are OK)

name = ' Hello World '    /single quotation mark
name = "Hello World"    //double quote
2, the operation of the string
(1) Concatenation of strings

(2) member operator operator: "In" "Not in"

str1 = ' Hello '
str2 = ' world '
str3 = ' OK ' and ' he
'            in str1//interpreting ' he ' is in str1, apparently ' he ' is in str1, so the result is true
STR3        not in STR2//Because the string in STR3 is not str2, the result is True
(3) String cutting: string[i:j: K]--I represents the starting position, J represents the end position, but does not include the contents of the J unit, K represents a character out of every K-character.


(3) string formatting:

Syntax: str% (the value you need to enter) to replace the value in parentheses with the value you want to enter in the template

3, to Output "There have 3 people" You can use the following syntax

num = 3
print (' There hava%d people '% (num))

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.