Python Learning Notes Chapter Fourth: Basic Concepts

Source: Internet
Author: User
Tags constant natural string in python

This chapter focuses on some of the basic concepts in Python that are often used and that you have to understand.

A literal meaning of a constant

The so-called literal constants are like 1, 2, 3, hello, hello, such numbers or strings, you can literally understand the meaning of the literal meaning of the constant.

Second, the number

There are four types of numbers in Python: integers, long integers, floating-point numbers, and complex numbers.

* 2 is an example of an integer

* 10000 is an example of a long integer (a long integer is a larger integer)

* 3.14 is an example of a floating-point number

* ( -5+4J) is an example of a complex number

Three, string

A string is a sequence of characters, or it can be understood to be a group of words.

How do I use strings in Python?

* Use single quotes (')

You can use single quotes to specify strings, such as ' Hello world '

* Use double quotes ("")

The string in double quotes is exactly the same as the string used in single quotes, such as "What ' your name?"

* Use three quotes ("" or "")

Using triple quotes You can specify a string of multiple lines, such as:

"" "What ' s your name?

My name is Song ""

* Escape character (\)

The escape character in Python is the same as the use and expression in the shell, in the case of the (backslash), it is noteworthy that if a single \ (backslash) appears on the end of a line, it means to continue writing on the next line, rather than escaping, which should be paid special attention to.

* Natural String

If you want to indicate certain special characters that do not require an escape character, you can specify a natural string that is specified by prefixing the string with the prefix R or R.

For example: R "My name are Song by \ n"

* Unicode string

Unicode is the standard writing of international text, and Python can also handle Unicode text by simply adding u to the front of the string. For example: U "This are a book"

* Strings cannot be changed

Once you create a string, you can't change it. I'll talk about why.

* cascading strings by literal meaning

If you put two strings adjacent to each other literally, Python will automatically cascade them, for example, ' What ' your name? ' is automatically converted to "What ' your name?"

Four, variable

A variable is a name that points to various types of values, and later when you use this value, you can refer directly to that name without having to write a specific value

The naming rules for variables are as follows:

* The first letter of the identifier must be a letter in the alphabet (uppercase or lowercase or _ underline)

* Other departments of the identifier name can consist of letters, underscores, and numbers.

* Identifier names are sensitive to case sensitivity.

* Examples of valid identifiers are: I, _my_name_, name_123

* Examples of invalid identifiers are: 2things, this is, my-name

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.