Formatted output, the underlying operator, the while loop

A, formatted output

  1. % S string placeholder

    name = input("Name:")
    age = input("Age:")
    job = input("Job:")
    hobby = input("Hobbie:")
    info = '''
    ------------ info of %s ----------- #这⾥的每个%s就是⼀个占位符,本⾏的代表 后⾯拓号⾥的 name
    Name : %s #代表 name
    Age : %s #代表 age 
    job : %s #代表 job
    Hobbie: %s #代表 hobbie
    ------------- end -----------------
    ''' % (name,name,age,job,hobbie) # 这⾏的 % 号就是 把前⾯的字符串 与拓号 后⾯的 变量 关联起来
    print(info)
    • String formatting, when the number of accounts and amount of padding to be consistent
    • %% - escaped, converted into a normal footprint%, when there% placeholder string, must be escaped with %%%, to get ordinary%
  2. % D /% i integer placeholder

    Accounting integer positions, corresponding to the filling must be an integer

  3. f"{}"

    print(f"""
    -------------info------------
    name: {name}  # {}内一般放变量,要放字符串需要加上''
    age: {age}
    sex: {sex}
    job: {job}
    hobby: {hobby}
    --------------end------------
    """)
    # f字符串拼接 -- 3.6版本以上才能使用

Second, the underlying operator

  1. Assignment Operators

    a = 1
    a += 1   # a = a + 1
    a -= 1   # a = a - 1
    a *= 1   # a = a * 1
    a /= 1   # a = a / 1
    a //= 1  # a = a// 1
    a **= 1  # a = a ** 1
    a %= 1   # a = a % 1
  2. Arithmetic Operators

    • Plus +
    • Less -
    • Take *
    • In addition to /
    • Divisible (except floor) //
    • Exponentiation **
    • Modulo%
  3. Logical Operators

    • not wrong, true or false, that is true nor false

    • and and, and, when both sides are true is true

      print(1 and 9)     # and 两边都是真的时候取and后面的内容
      print(False and 0) # 两边都是假的时候取and前面的内容
    • or, or, or, while there is true is true

      print(1 or 2)   # or 两边都为真的时候取or前面的内容
      print(1>2 or 2) # 有一边为真的时候返回真的内容
      print(0 or 2>3) # 两边都为假的时候取or后面的内容
    • Order of operations

      () > not > and > or

  4. Comparison Operators

    == != > >= < <=

  5. Member operator

  • in may determine whether the string that appears in the xxx xxxxx string

  • not in

    a = "abc"
    print("a" in a)   # True
    print("A" in a)   # False
    print("a" not in a)  # False
  1. Identity operator
  • It is a value judgment is not the same, pointing to the same virtual memory
  • is not

Third, coding

  • ASCII (American Standard Code for Information Interchange, American Standard Code for Information Interchange) is based on the Latin word ⺟ of ⼀ sets of computer coding system, the main Use to display modern English and other European ⻄ Language, which is used only for a maximum of 8 bit to represent (⼀ bytes byte), namely: 2 ** 8 = 256, therefore, the ASCII code can only represent up to 256 symbols.

  • GBK, GB code accounted Using two bytes The corresponding ASCII code GBK directly compatible because the underlying computer is Using English files written. You do not support the British files is certainly not ⾏. ⽽ British files have not been used the ASCII code. So GBK to be compatible with ASCII.

  • Unicode, Unicode, English 2 bytes, 4 bytes Chinese

  • UTF-8: 8 bits per character minimum number of bytes per character indefinite Use according text about the content is encoded into ⾏ particular destination time frequency before USING A HIGH ⼀ most kinds of encoding.... English 1 byte, 2 bytes European languages, Asian characters, 3 bytes.

  • Unit Conversion

    8bit = 1Byte
    1024Byte = 1KB
    1024KB = 1MB
    1024MB = 1GB
    1024GB = 1TB

Four, while circulation

  • while condition A:
    block A (loop) # A when the conditions established operating cycle thereof
    else:
    block B # A when the condition is not satisfied, operation block B

    index = 1
    while index < 11:
      if index == 8:
    '''break,终止本层循环,不运行后面的代码,如果循环是通过break退出的. 那么while后⾯的else将不会被执⾏, 只有在while条件判断是假的时候才会执⾏这个'''
    '''continue,跳出本次循环,进行下次循环,重新判断条件,不运行后面的代码'''
    else
      else:
          print(index)
      index = index+1
    else:
      print("你好")

Guess you like

Origin www.cnblogs.com/douzi-m/p/11904672.html