Python Encounters--string (i)

Source: Internet
Author: User

1. There are 4 ways to express a string:
Single quote: "'
Double quotes: "
Three single quotes: "'
Three double quotes: "" "or" "
Content in quotation marks is the contents of a string

2. The difference between single and double quotation marks:
Double quotation marks in single quotation marks do not end with a terminator
Eg: ' I am A "a" '-->i am a "a"
Single quotation marks in double quotation marks do not count as Terminator
Eg: "I ' m A a"-->i ' m A A

Three quotes: What you see is what you gain
Line breaks in three quotes are automatically converted to newline characters
Enclose single and double quotation marks in three quotation marks
eg
' See '
That
Gain "
--
See '
That
Proceeds

3. Escape character:
Use a backslash (\) to represent a character with some characters
eg
\ '--'
\ "--"
\ n-Line
\f--page break
...
Other escape characters please own Baidu

4. ASCII code:
You can enter the man ASCII command under Terminal to view the encoding

5.raw string (Raw String)
The backslash within a string is not used as an escape character
Eg: "r=c:\windows\n\ ..."-->r=r=c:\windows\n\ ...

6. String arithmetic
+ += * *=
+: string concatenation
eg
A= "a"
B= "B"
C=a+b
-
A= "a"
B= "B"
C= "AB"
+ =: string concatenation assignment
eg
A= "a"
B= "B"
A+=b
-
A= "AB"
B= "B"
*: String repetition
eg
A= "a"
B=a*2
-
A= "a"
b= "AA"
*=: String Duplicate Assignment
eg
A= "a"
A*=3
-
A= "AAA"

7. String comparison:
> >= < <= = = =!
The comparison of strings is determined by comparing the ASCII encoded values of the bit string to determine the size or equality
eg
"A" > "B"
ASCII encoding of A is 97
Do not understand ASCII encoding is 98
So the result of "a" > "B" is false

8, In/not in
Determine if a value exists/does not exist in the container

9. String index
Find the corresponding character by subscript
Subscript starting from 0

10. String Slicing operations:
s[(start index B): (End index e):(step s)]
Eg:s= "ABCDEFG"
S[1,5,2]-->b,d
Indexes 1 to 5 (not including 5) i.e. BCDE, with step 2, remove B and D

11. String Method:
S= "ABCDEFG"
S.lower Variable Lowercase string
S.upper variable Capitalization string
S.title First Letter Capital
S.strip removing left and right empty strings
...

12. String function:
Len (s) Output string length
Max (s) characters in the output string for the maximum ASCII value
Min (s) character of the ASCII minimum in the output string
...

13. Formatting expressions for strings:
% parameter value
% (parameter 1, parameter 2 ...)

Python Encounters--string (i)

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.