Python data type (i)

Source: Internet
Author: User

There are 6 main types of Python3: numbers, strings, lists, tuples, dictionaries, and collections.

Number types include: reshape, floating-point number, plural, boolean, and no long in Python3.

According to the use, can be directly assigned value. Such as:

where type () can be used to view the data type of an object. There is no need to define an object type in Python, and Python automatically recognizes the type of input based on the data entered.

There are 3 definitions of strings: single quotes ", double quotes", Sanchong quotes "" "" ", where Sanchong quotes can be used for multiline descriptions, multiple lines of comments in code, and doc descriptions in functions.

>>> str1 = ' Hello World ' >>> type (str1) <class ' str ' >>>> str2 = "Hello World" >>> Type (STR2) <class ' str ' >>>>>>> STR3 = "" "Hello World" "" >>> type (STR3) <class ' str ' >>>>

When single quotes are present in a string, double quotation marks are required, such as:

However, when single and double quotation marks are present in a string, the \ Escape character is used to escape single or double quotes to ordinary characters:

>>> ZXL = "Let's" Go ""  File "<stdin>", line 1    ZXL = "Let's" go "                   

Sanchong quotation marks can be used to define multiple rows of data, or to comment out multiple lines, or for a doc document in a function:

  

There are 2 operations for strings: indexes, slices.

Index: Like other languages, indexes are indexed by label, the string index starts at 0, increments sequentially, and Adbde the index value is 01234. Such as:

Slice: Indicates that some value in the string is taken out, string A, slice represents a[start:end:step], which means that the step step is incremented from start to end, and does not contain the character of end. Such as:

>>> zxl ' ABCDE ' >>> zxl[1:4]  #表示从1号字符取到 (4-1) character, index zlx[1]zxl[2]zxl[3] ' BCD ' >>> zxl[:4 ]   #表示从开始到第3号字符. ' ABCD ' >>> zxl[4:]  #表示从第4号字符到结束 ' e ' >>> zxl[2:]  #表示从第2号字符到结束 ' CDE ' >>> zxl[::1]   #表示从开头到结束, 1 steps per Interval ' ABCDE ' >>> zxl[::2]  

In Python, the index can be negative, that is, the last character of the string is indexed as-1, and the forward number is-2,-3,-4 ..., for example:

>>> zxl[-1]  #表示最后一个字符 ' e ' >>> zxl[-4:-1]  

As can be seen, take the direction of the BCD, if you take from the back, you need the last parameter, the negative value is from the back to the forward, positive value for the past, such as:

  

Python data type (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.