Foundations python operators and coding

  1. while loop

    • What is the cycle?

      • It is to constantly repeat one thing
    • while - back with key conditions: There loop,

      • Body condition is true, execution cycle in vivo, is not performed is false
    • while else

      • Both as a whole, the equivalent of if else, if they break. Will not be executed else the code below

        #死循环
        while True :
            print("爱情买卖")
        
        #循环两次
        num = 2
        while num > 0 :
            print("爱情买卖")
            num = num - 1
        
        num = True
        while num :
            print(123)
            num = False
        else:
            print("a")
        #输出123 和 a ,因为第二次循环,当num为假时,开始执行else  里边的语句
        
        num = True
        while num :
            print(123)
            break
        else:
            print("a")
        #打印123,因为break终止循环时。不会执行else里边的语句,他们是一体的
    • break terminates the loop

      • break the cycle bottom in writing, through the bad end of that, and when this cycle is not executed break below
      • break the cycle must be written in vivo, in vitro unloading cycle will complain
    • contioune out of this cycle, the next cycle continues

  2. Formatted output

    • Placeholder: %
      • As long as the string back with%% is equivalent to the string inside there is a placeholder
      • Accounting positions must be filled and correspondence
      • Filling filled in the order
      • % S - string representing the position (% s number, string can be filled)
      • % D |% i - accounting for Digital Position
      • %% - escape character escaped as%
    • Formatted output f "{} {} {}"
  3. Operators

    • Arithmetic operators

      • Arithmetic + - * / modulo% power (power) ** Results integer (rounding the like) in addition to the floor, also called // 5 // 2 = 2
    • Comparison Operators

      • Less than <Greater than> not equal == equal! = Less than or equal, greater than or equal
    • Assignment Operators

      • = Assignment. Since plus a + = 1, similar to a = a + 1, decrement a - = 1, * =. / =. ** =. % =. // =.
    • Logical Operators

      • And: and or: or non-: not
      • Digital zero are true
      • Priority: () -> not -> and -> or
    • Member operator

      • in again

      • not in not in

      • a = "jingjunke"
        if b not in a :
            print("不在")
        else:
            print("在")
  4. coding

    • ascii
      • ascii character set encoding is early Americans invention. Does not support Chinese and other languages, only supports English. In Ascii, one English one byte characters.
      • Does not support Chinese
      • A letter occupies one byte
    • gbk (GB)
      • GBK encoding is a Chinese invention, support Chinese and English. A Chinese character occupies two bytes
      • English one byte, two-byte Chinese
    • unicode (Unicode)
      • Unicode is Unicode. Supported languages ​​encode multiple countries. In the present encoding four bytes are Chinese and English
      • Chinese four bytes
      • English four bytes
    • utf-8
      • utf - 8 is really on the Unicode encoding update developed, also support Chinese and English, but in order to save space. Chinese and English are variable length byte. An English one byte, two bytes in Europe, Asia accounted for three bytes
      • English one byte
      • Europe 2 bytes
      • Asian 3 bytes, three bytes Chinese
    • Unit Conversion
      • 1Bytes = 8 bit <----> 1 byte = 8 <------> 1B = 8b
      • 1KB = 1024B
      • 1MB = 1024KB
      • 1GB = 1024MB
      • 1TB = 1024GB
      • 1PB = 1024TB
    • win code is gbk, liunx code is utf-8, mac code is uft-8

Guess you like

Origin www.cnblogs.com/jingjunke/p/11408953.html