2018-05-27--python Seventh Day

Source: Internet
Author: User
Tags set set

Set set: Unordered immutable values (numbers, characters, Ganso) made up of different elements (which are automatically de-weighed)

s = {1,2,3,4,5}

S=set (' Hello ')

Set.add (x)//add element x to set

Set.clear ()//condition Set

S=set.copy ()//

Set.pop ()//randomly delete an element?

Set.remove (x)//delete x element, x not present error

Set.discard ()//delete x element, x does not exist without error

(set&x==) set.intersection (x)//Take the intersection of X and set

(set|x==) Set.union ()//Take x and set of the set

(set-x==) Set.difference ()//Take the difference set of X and set

(set=set-x==) set.difference_update (x)//Take Set-x difference set and update set ... Several other calculations also have an update

(set^x) set.symmetric_difference (x)//Take x and set cross complement sets

Set.isdisjoint (X,x1 ... )//Determine if set and X have intersection, return BOOL. X can be multiple

Set.issubset (x,x1 ...) Determine if set is a subset of x?

Set.issuperset (x,x1 ...) Determine if x is a subset of set

Set.update (x)//update the value of set to the value of x, X is an iterative value of 4

S=frozenset ()//definition cannot become a collection

String formatting: Percent semicolon, format

\033[num;1m%[(name)][flags][width]. [Precision]type\033[0m

\033[NUM;1M: Add color

Name: Select the specified key

flags:+//right, positive before plus,-//left aligned, positive before unsigned, space//right-aligned, positive before plus space, 0//right-aligned, positive before unsigned

Width: Occupied precision: Number of digits after the decimal point

Type

    • S, gets the return value of the __str__ method of the passed-in object and formats it to the specified location
    • R, gets the return value of the __repr__ method of the passed-in object and formats it to the specified location
    • C, Integer: Converts a number to its Unicode corresponding value, 10 binary range is 0 <= i <= 1114111 (py27 only supports 0-255); character: add character to specified position
    • O, converts an integer to an octal representation and formats it to a specified location
    • X, converts an integer to a hexadecimal representation and formats it to a specified location
    • D, converts an integer, floating-point number to a decimal representation, and formats it to a specified position
    • E, converting integers, floating-point numbers to scientific notation, and formatting them to a specified location (lowercase e)
    • E, converting integers, floating-point numbers into scientific notation, and formatting them to a specified position (uppercase E)
    • F, converts an integer, floating-point number to a floating-point number representation, and formats it to a specified position (the default is 6 digits after the decimal point)
    • F, ibid.
    • G, auto-adjust convert integers, floating-point numbers to floating-point or scientific notation (more than 6 digits in scientific notation), and format them to a specified location (if scientific counts are e;)
    • G, auto-adjust convert integers, floating-point numbers to floating-point or scientific notation (more than 6 digits in scientific notation), and format them to a specified location (if scientific counts are e;)
    • %, when there is a format flag in the string, a percent sign is required

msg= ' xxx%s sssss%s '% (' x1 ', ' x2 ')//or x is directly a variable name

msg= "Ssssss% (K1) s% (K2) d"%{"K1": "V1", "K2": "V2"}

Print (' x ', ' y ', ' z ', seq= ' n ')//seq use delimiter n

Format:

[[Fill]align] [Sign] [#] [0] [Width] [,] [. Precision] [Type]

    • Fill "optional" white space filled with characters
    • Align "optional" alignment (required with width)
        • <, content left justified
        • Content right-aligned (default)
        • =, the content is right-aligned, the symbol is placed to the left of the padding character, and only valid for numeric types. Even: symbol + filler + number
        • ^, content centered
    • Sign "optional" with unsigned numbers
      • +, positive home Plus, minus plus negative;
      • -The plus sign does not change, minus is negative;
      • Spaces, plus spaces, minus signs and negative;
    • # "optional" for binary, octal, hex, if added #, 0b/0o/0x is displayed, otherwise not displayed
    • , "optional" adds a delimiter to the number, such as: 1,000,000
    • width "Optional" format the size of the placeholder
    • . Precision "optional" decimal digits reserved Precision
    • type         "optional" format type
      • incoming parameter for string type
        • S, format string type data li>
        • blank, unspecified type, default is None, same as S
      • incoming parameter for integer type
        • B, 10 rounding The number is automatically converted to a 2 binary representation and then the
        • c is formatted, and the 10 binary integer is automatically converted to its corresponding Unicode character
        • d, decimal integer
        • o, 10 binary integers are automatically converted into 8 binary representations and then formatted;
        • x, which automatically converts 10 binary integers to 16 binary representations and then formats (lowercase x)
        • x, Converts a 10-decimal integer into a 16-binary representation and then formats (uppercase X)
      • incoming float or decimal type   parameter
        • E, converted to scientific notation (lowercase e) is represented, then formatted;
        • E, converted to scientific notation (capital E), and formatted;
        • F, converted to floating point (6 bits left after the default decimal point), and then formatted;
        • F, converted to floating point (6 bits left after the default decimal point), and then formatted;
        • g, automatically toggle between E and F
        • G, automatically toggle between E and F
        • %, display percent (6 digits after the decimal point by default)

tpl ="i am {}, age {}, {}".format(x1,x2,x3)//x可以是任意类型 , in order to take

tpl  = "i am {}, age {}, {}" . format ( * [ "seven" 18 ‘alex‘ ])* Upload List tpl  = "i am {num}, age {num}, really {num}" . format ( "seven" 18 )//num索引位置 tpl  = "i am {0[0]}, age {0[1]}, really {0[2]}" . format ([ 1 2 3 ], [ 11 22 33 ]) tpl  = "i am {num}, age {num}, really {num}" . format ( * [ "seven" 18 ])//*传列表 tpl  = "i am {name}, age {age}, really {name}" . format (name = "seven" , age = 18 )Chuan Yuan zu tpl  = "i am {name}, age {age}, really {name}" . format ( * * { "name" "seven" "age" 18 })  //**传字典 tpl  = "i am {:s}, age {:d}, money {:f}" . format ( "seven" 18 88888.1 )By type, in order tpl  = "i am {:s}, age {:d}" . format ( * [ "seven" 18 ]) tpl  = "i am {name:s}, age {age:d}" . format (name = "seven" , age = 18 ) tpl  = "i am {name:s}, age {age:d}" . format ( * * { "name" "seven" "age" 18 }) tpl  = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}" . format ( 15 15 15 15 15 15.87623 2 )//按顺序转换数字 tpl  = "numbers: {0:b},{0:o},{0:d},{0:x},{0:X}, {0:%}" . format ( 15 )//按索引转换数字 tpl  = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X}, {num:%}" . format (num = 15 )

Function:

Definition method: def name (x):

.......

return x

() define the parameters in

Procedure: is a function that has no return value

Parameter: The variable used when defining the function, only the memory is allocated when the function is called, and then returned to the main function, no longer used

Arguments: Actual variables used in the main function

Local variables: Variables defined in a subroutine

Global variables: Variables defined at the beginning of the entire program

Suddenly found out that Alex big guy shared the nineth issue of video hhhhhh I'll see you today.

2018-05-27--python Seventh Day

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.