Python Study Notes 1-assignment and string

Source: Internet
Author: User

Reading this study note requires a certain language base. If you have nothing to say, let's start.

I. Assignment and numbers

[Overview]
Python assignment is simple:

Number = 1 # Number = 2 + 2 # support for addition, subtraction, multiplication, division, number = (1 + 2j) * (1-1j) # support for complex operations
Ii. String

[Overview]
STR = "Hello, world! "# String
You can also use three consecutive single quotes or double quotation marks to represent a string, similar to the PRE Tag in HTML, which can be directly output in actual format.
Example:

Print "" * "'% """

[String operation]
Strings can be connected by the + operation (or put together), or the * operation can be used for repetition.
Example:

WORD = 'test' + 'er' word2 = word * 2

Output:

Tester testertester

AndC LanguageHowever, Python strings cannot be modified. For example, if word = 'hello', you want to change it to word = 'aello ', you cannot execute a statement like word [0] = 'A. But you can do this:

Word2 = 'A' + word [1:]

We can easily intercept a segment in a string. For example, we can intercept three characters starting with subscript 2 and ending with subscript 4, that is, word [2: 5].

[Unicode string]
Since python2.0, Unicode strings are supported. It is very easy to create a unicode string:

WORD = u'hello world! "

The "U" before the quotation marks indicates that the string is a unicode string. It can also be encoded with Unicode characters:

WORD = u'hello \ u0020world! ", U0020 is a space character.
Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.