Basics for python

1.python installation environment

  • python2
  • python3
  • Add the environment variable after installation

2. coding

  • The earliest encoding ASCII code, mainly English, numbers, characters one byte (byte), eight (bit), on behalf of a character
  • unicode Unicode, all languages ​​are included in the basic, four-byte, 32, represent a character, occupy large memory space
  • utf-8 is a byte Unicode compression English, eight, two bytes in Europe, 16, Chinese three bytes, 32 bits.
  • gbk GB two byte code, sixteen
  • gb2312

3. Variables

  1. Naming conventions
    • Combination of letters, numbers and underscore
    • You can not start with a number
    • It can not be keywords
    • Variable names to be meaningful
    • You can not use Chinese
    • You can not use Pinyin
    • Not too long, you can use the abbreviation
    • Usually connections are underlined, for example:.. Hello_world unusual hump body HelloWorld

4. Constant

  1. Absolute constants do not exist in python
  2. General use all capital letters on behalf of constants

5. Comment

Some unlikely to write some description can understand, so that the program easy to understand. Annotated code is not executed

  1. #表示单行注释
  2. """
    表示多行注释
    """

6. User interaction

  • python3 the input ( "Enter") which put the precautionary statements
  • All the received string (str)

7. Process Control

  1. if, else statements

    '''
    if 条件:满足条件则运行
    缩进四个空格   操作
    elif 条件:上面不满足运行这个
        操作
    else:否则,也就是上面全不满足运行
        操作
    '''
  2. while loop

    '''
    while 条件:如果条件满足则一直重复,当条件为Ture时为死循环
        操作
        break退出当前此循环
        exit(0)直接退出运行的代码,后面有代码也不再运行
        continue跳出本次循环,进入下次循环,也就是再次从while开始此循环
    '''
  3. for loop

    """
    for 变量名 in 可迭代对象:#可以一个一个往外取的对象
        print(变量名)
    把可迭代对象中的每个值赋值给变量
    """

8. Output Formatting

  1. Placeholder% s,

    """
    name="ice"
    age=22
    s="我叫%s我今年%s岁" %(name,age)   其中%s是占位符,后面%(为填充的变量)有多少占位符就填充多少
    """
    
    #如果格式当中用到%号则用两个百分号代替
    """
    name="ice"
    s="我叫%s,我手机电量剩10%%了"%(name)
    """

9. Operator

+ plus
- Less
* Multiply
/ except
== equal
// Divisible, for example: 10 @ 3 == 3
% Modulo take the remainder, 10% 3 == 1 e.g.
** Power, e.g., 2 ** 3 == 8
!= not equal to
<> not equal to
> more than the
< Less than
>= greater or equal to
<= Less than or equal
= Assignment equal
+= Addition assignment equal
-= Subtraction assignment equal
/= Equal division assignment
*= Multiplication assignment equal
** Equal power assignment
%= Assignment equal modulo
//= Divisible equal assignment
not Non, true or false, that is true nor false.
and And both sides are all true is true,
or Alternatively, both sides is true is true
Priority ()> comparison operator> not> and> or
notes Wherein 0, "" [] {} () is False

Guess you like

Origin www.cnblogs.com/nieice/p/10968979.html