Python base -> strings, numbers, variable

Python basis: strings, numbers, variables

1. string (an expression information)

a. Use quotes to create a string

. B single and double quotation marks, three marks: ',', '', '' '

. C print functions: print ( 'hello', end = ','); print ( 'world', end = ';')

D. and display formats associated string print function should occur, the print function can specify a different end of the string.

is. ascii art

    """
     #####                          #######                      
    #     #   ##   #    # ######    #     # #    # ###### #####  
    #        #  #  ##  ## #         #     # #    # #      #    # 
    #  #### #    # # ## # #####     #     # #    # #####  #    # 
    #     # ###### #    # #         #     # #    # #      #####  
    #     # #    # #    # #         #     #  #  #  #      #   #  
     #####  #    # #    # ######    #######   ##   ###### #    # 
    """

. F using the escape sequence can use special characters in the string, the escape sequence consists of two characters, such as: \ t

Using the escape sequence string itself achieve some results are not available. print ( "\ n hello \ tworld \ n")

'\ T' Tabs can be provided not only offset in the text, the text may be aligned in columns.

g. strings addition and multiplication operation, i.e., repeated n times with the string concatenation string. Line continuation character \ can not be in a string.

H. to represent the text string.

2. Digital (an expression information)

a. an expression is composed of the values ​​and operators can be reduced to another value of the sequence.

b. / true division result obtained floating point, integer // integer division results obtained, removing the decimal portion. 7/3 = 2.33333, 3 @ 7 = 2.

3. Variables

a. using the variable information storage and manipulation, and the use of variables to access a variety of information organization.

b. variable provides a means to identify and access information without having to remember a specific location information in the computer's memory, only one variable to find it.

c. Create a variable and assign it a value, and thus variable points to this value. Assignment statement for a variable assignment, if the variable does not exist then it will create assignment.

d. Technically speaking, the assignment statement sets the value of the right of the equal sign to save computer memory, and then let the left operand to refer to this value. Therefore, the variable "got" a value, not a variable "is assigned" a value.

e. Use variable, the variable is created after the reference value can go up. Easy to place variable is that it can be referenced as the value of their own to use.

f. valid variable name. Variable names can only contain numbers, letters, and the underscore; variable name can not start with a number.

g. Good variable names. Select the name has a descriptive variable names clear. A short temporary variable names. Variable names consistent style, such as the hump, underlined. Follow language habits, variable names begin with a lowercase letter, avoid variable names first character is underlined by the names that begin with an underscore in python that have special meaning. The variable name is not too long, try to keep the variable name within 15 characters, self-documenting code that is no comment can easily understand the program functions.

H. get user input, using the stored variables. input function. Call the function, representing an action, pass parameter information, perform an action, get returns the result.

g. using a method to create a new string of the character string on the basis of the existing string. Such as: upper (), lower (), title (), strip (), replace (). All string methods are only created a new string, without affecting the original string.

h. If the program produces unexpected results did not collapse, it indicates that there is a logic error, logical error correction may be the most difficult bug, because the program does not crash without any error message can provide clues, can only behavioral observation program and carefully review code.

I. strings and plus numbers are valid for the operator. Using the same operator on different types of values, which is called operator overloading. As long as the realization of the number, operator overloading will make the code more concise.

j. the type of conversion. float (), int (), str ().

K. compound assignment operators. The original value of the variable to do some calculations and then reassigned back. This is common, so these operators will provide a nice shortcut for daily tasks. X =. 5 is equivalent to X = X . 5.

Guess you like

Origin www.cnblogs.com/mindshare/p/11404868.html