Python tutorial reading Python basic and basic variables

Source: Internet
Author: User
Use Python as a calculator division operation

When using/representing division operations, we generally get floating-point numbers, and if we need to get integers, we can use the operator//

Remainder calculation%

Power exponentiation

System built-in variables _

Built-in variable _, which stores the most recent results.

String

Strings can be concatenated (glued together) by the + operator and can be duplicated by *, and adjacent two string literals are automatically concatenated together.

Error usage:

x = "123"y = "456"x y #错误,SyntaxError: invalid syntaxx + y #正确x "123" #错误

Python does not have a separate character type; a character is a simple string with a length of 1. And the string has an index. When the index is negative, the calculation is started from the right

  1. In addition to indexes, slices are supported. The index is used to get a single character, and the slice lets you get a substring. The slice contains the starting character and does not contain the end character .
  2. Python gracefully handles the meaningless slicing index: an oversized index value (that is, the subscript value is greater than the actual length of the string) will be replaced by the actual length of the string, when the upper boundary is larger than the bottom edge (that is, the slice left value is greater than the right value) returns an empty string
  3. Python strings cannot be changed-they are immutable. Therefore, assigning a location to a string index results in an error:

Python tutorial reading Python basic and basic variables

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.