The basis of the contents of -2

A, while circulation

while: the condition is satisfied for an infinite loop

  • structure:
while 条件:
    循环结果
  • Examples
while True:
    print("一号")
    print("二号")
    print("三号")
  • How to terminate the loop

    • Changing conditions

      #实例
      flag = True
      while flag:
          print(1)
          print(2)
          flag = False
          print(4)
          print(5)
    • break: exit loop when it encounters a break cycle

      while True:
          print(1)
          print(2)
          break
          print(3)
          print(4)
      
      #只会输出1 2 不会输出 3 4
    • continue: skip this cycle

      a = 0
      while a < 5:
          a += 1
          if a == 3:
              continue
          print(a)
  • Exercise 1: 0 to 100 Digital Print

    num = 0
    while num < 101:
        print(num)
        num += 1
  • Exercise 2: Print + 1 + 2 + 3 .... 100

    num = 1
    count = 0
    while num < 101:
        count += num
        num += 1
    print(count)
  • while else structure

    while 条件:
        循环体
    else:
        结果
    • Examples

      count = 1
      while count < 5:
          print(count)
          count += 1
      else:
          print("结束了。。")
    • When the break, and will not go else

Second, formatted output

% : Placeholder

symbol Explanation
%s Formatted as a string
%c Formatting characters and their ASCII code
%d Integer format
in% Unsigned int format
%f Format floating point numbers, the point precision may be designated
%% Output% (percent sign format string contains, must %%)
  • Example:

    name = "小明"
    age = 14
    message = "你好,我叫 %s,年龄 %d" %(name,age)
    print(message)
  • Note: The number in parentheses and order must be consistent

  • In the output format to express the percent sign, plus a percent sign in front of the percent sign

    name = "小明"
    age = 14
    message = "你好,我叫 %s,年龄 %d,进度1%%" %(name,age)
    print(message)

Third, the operator

3.1 operator class

  • Arithmetic operators
  • Logical Operators
  • Comparison Operators
  • Copy operator
  • Member operator
  • Identity operator
  • Bitwise Operators

Arithmetic operators 3.2

Operators description
+ plus
- Less
Multiply
/ except
% Modulo
** power
// Take divisible

3.3 Comparison Operators

Operators description
== equal
!= not equal to
> more than the
< Less than
>= greater or equal to
<= Less than or equal

3.4 Assignment Operators

Operators description
= Simple assignment operator
+= Addition assignment operators, for example: a + = 2 is equivalent to: a = a + 2
-= Subtraction assignment operator, for example: a - = 2 is equivalent to: a = a - 2
*= Multiplication assignment operators, for example: A = 2 is equivalent to: A = A 2
/= Division assignment operator, for example: a / = 2 is equivalent to: a = a / 2
%= Modulo assignment operators, for example: a% = 2 is equivalent to: a = a% 2
**= Power assignment operators, for example: a ** = 2 is equivalent to: a = a ** 2
//= Take divisible assignment operators, for example: a // = 2 is equivalent to: a = a // 2

3.5 Logical Operators

Operators description
and versus
or or
not non-

Priority: in the absence () of

not > and > or

The consent of the priority cases, calculated from left to right

  • Case 1: the operational sides are relatively

    print(2 > 3 and 3 < 4 or 5 < 6)
  • Case 2: Both sides are integers

    print(8 or 5)
    print(0 or 3)
    
    # x or y : x为真,值为x;x为假,值为y
    # x and y : x为真,值为y;x为假,值为x

in and not in: determining whether an element in the string, a tuple, list or dictionary

Fourth, the coding

4.1 编码类别

  • ASCII:美国信息交换标准编码
  • 国标:中华人民共和国国家标准信息交换用汉字编码
  • GBK:GB码的扩展字符编码
  • Unicode:将世界上所有字符都收入的编码
  • UTF-8:根据不同字符选择编码长度

4.2 ASCII

  • 规定了一个字符用一个8位的二进制数表示(0000 0001)
  • 最多只能表示256个字符,即 2**8=256
  • 8bit = 1byte

ASCII编码

4.3 GBK 国标码

  • 规定一个字符用2个8位的二进制数表示,即16位(0000 0001 0001 0011)
  • 可以表示65535个字符,即 2**16 = 65535
  • 兼容了ASCII,扩充了中文字符

4.4 Unicode UTF-8

  • 号称收纳了世界所有字符的编码
  • 扩充到了32位,也就是4个8位的二进制数
  • 可以表示2**32个字符
  • 由于太过浪费,提出了UTF-8,可变长度的编码
  • UTF-8是对Unicode编码的压缩和优化,将所有字符进行分类:ASCII编码的内容用1个字节、欧洲字符用2个字节。。。

4.5 单位转换

8bit = 1byte

1024byte = 1KB

1024KB = 1MB

1024MB = 1GB

1024GB = 1TB

1024TB = 1PB

1024PB = 1EB

1024EB = 1ZB

1024ZB = 1YB

1024YB = 1NB

1024NB = 1DB

Guess you like

Origin www.cnblogs.com/os-linux/p/11123297.html