Python Learning In Debian Linux-Basic Knowledge

Source: Internet
Author: User
Tags natural string processing text

The basic data types in Python are numbers and strings. The following describes the basic knowledge of Python, including numbers, strings, variables, identifiers, and objects.

1. Number

In python, the number types include integer, long integer, floating point, and plural.

    • 2Is an integer.
    • A long integer is a larger integer.
    • 3.23And52.3e-4Is an example of floating point number. E indicates the power of 10. Here,52.3e-4Indicates52.3*10-4.
    • (-5 + 4j)And(2.3-4.4.7)Is an example of a plural number.

InputCode:

Running result:

2. String

A string is a string of characters.

  • Use single quotes (')

    A string can be enclosed in single quotes, such'Hello world! '. All spaces, that is, spaces and tabs are retained as they are.

  • Double quotation marks (")

    The strings in double quotation marks are exactly the same as those in single quotes. For example"Hello world!".

  • Use three quotation marks (''' or """)

    Three quotation marks can be used to represent a multi-line string. You can use single quotes and double quotes freely in three quotes. For example:

    ''' "Hi" Jim said,

    'Good morning! 'Tom said
    '''

  • Escape Character

    To include a single quotation mark (') in a string, use the escape character to convert the stringWhat \'s your name? '.You can also use double quotation marks, such"What's your name? "Similarly, to use double quotation marks in a double quotation mark string, escape characters must be used. In addition, escape characters can also be used.\\To indicate the backslash itself.

    Note: In a string, a separate backslash at the end of the line indicates that the string continues in the next line, rather than starting a new line. For example:


    "This is the first sentence .\
    This is the second sentence ."

    Equivalent"This is the first sentence. This is the second sentence ."

  • Natural string

    If you want to indicate strings that do not require special processing such as escape characters, you need to specify a natural string. A natural string is prefixed by a string.ROrR. For exampleR "newlines are indicated by \ n".

  • Unicode string

    Unicode is a standard method for writing international text. If you want to write text in your native language, such as Hindi or Arabic, you need an editor that supports Unicode. Similarly, Python allows you to process Unicode text-you only need to add a prefix before the stringUOrU. For example,U "this is a unicode string .".

    Remember to use Unicode strings when processing text files, especially when you know that the file contains text written in a non-English language.

  • The string is unchangeable.

    Once a string is created, it cannot be changed.

  • Literally connected strings

    If you put two strings adjacent to each other literally, they will be automatically connected by python. For example,& Apos; what \'s & apos; your name? 'Will be automatically converted"What's your name? ".



    Note:Single quotes and double quotes strings are exactly the same-they are not in any way different.

    Enter the code:

    Running result:

Comments for regular expression users
Be sure to use natural strings to process regular expressions. Otherwise, a lot of backslash is required. For example, the backward reference character can be written'\ 1'OrR' \ 1'.

3. Variables

You can use variables to store everything. Variables are only part of the memory used to store information in computers. Unlike constants in the literal sense, you need to name the variables for ease of use.

4. identifier

A variable is an example of an identifier.IdentifierIs used to identifySomething. Follow these rules when naming identifiers:

    • The first character of an identifier must be an uppercase or lowercase letter or an underscore ('_').

    • Other parts of an identifier name can be uppercase or lowercase letters, underscores ('_'), or numbers (0-9.

    • The identifier name is case sensitive. For example,MynameAndMynameNoAn identifier. Note: the lower case n in the former and the upper CASE n in the latter.

    • ValidThe following are examples of identifier names:I,_ My_name,Name_23AndA1b2_c3.

    • InvalidThe following are examples of identifier names:2 things,This is spaced outAndMy-name.

Variable can process different types of values, calledData Type. The basic types are numbers and strings.

5. Object

PythonProgramEverything used is calledObject. This is in a broad sense. So we won't say "XX"Things", We say,"Object".
Python is an object that contains numbers, strings, and even functions.

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.