Python Concise Tutorial Learning Notes

Source: Internet
Author: User
Tags natural string

1. use three quotation marks ( "" or "" ")

Using the three quotes, you can indicate a multiline string. You can use single and double quotation marks freely in three quotes. For example:

str= "This is a multi-line string. the first line.
The second line.
"What ' s your name?," I asked.
He said "Bond, James bond."
" "

2. Natural string

If you want to indicate certain strings that do not require special handling such as escape characters (invalid escape symbols), then you need to specify a natural string. Natural strings are specified by prefixing r or specifying the string R . such as str= r"Newlines are indicated by \n" .

The print (str) result is:newlines is indicated by \ n.

Be sure to use a natural string to process the regular expression. Otherwise, you will need to use a lot of back slashes. For example, a forward reference can be written as ' \\1 ' or R ' \1 '.

3. The string is immutable

This means that once you create a string, you can no longer change it.

4. string literals by literal meaning

If you put two strings next to each other by literal means , they will be automatically connected by Python. For example, ' what\ ' s '   your Name? ' " What ' s    your name? "

5. Object

6. Variable

7. Logical lines and physical lines

If you want to use more than one logical line in a physical line, you need to use a semicolon (;) to specifically indicate this usage. semicolon represents the end of a logical line/statement. For example: I=5;print (i)

Example of writing a logical line in multiple physical rows. It is called the Explicit row connections

s =  " is a string. \
This continues the string. '

print ( s)

输出结果为:This is a string. This continues the string.

在逻辑行中使用了圆括号、方括号或波形括号的时候,也可以使多个物理行对应一个逻辑行,这被称为暗示的行连接

str=[1,23,"hello"
,"ok"]
print(str)

结果为:[1, 23, ‘hello‘, ‘ok‘]


Python Concise Tutorial Learning Notes

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.