Python basis (2)

Python basis (2)

The basic syntax elements

  • Note the use of single-line #, multi-line comments work string may be used to achieve (action annotated increase readability)

  • A written statement at the end of the semicolon is not recommended, unless you want to write multiple statements in a row

  • Python source file name suffix .py

  • Installation programming specification, the first row Python source file is often specified annotation content corresponding to the current script interpreter, the second row is usually annotation content specified source file using character encoding

  • Keyboard input data calls the built-in function input, outputs the data to the calling terminal window built-in functions print

 

Basic data types

int: integer, you can use a different hexadecimal representation, such as -123,0o123 (octal), 0x123 (hexadecimal), 0b101 (binary)

float: floating point number (i.e. decimals), expressed in two forms: decimal and scientific notation, such as 3.14; -1.23; -1.3e3; 3.2e-2, etc.

bool: Boolean type, only one word face amount: True and False

str: string, string, string of characters in the string Python3 agreed to Unicode encoding, there are three forms of representation, single and double quotation marks and three marks, which can add a prefix r, represents the original string (Raw String), coming all the characters literally interpreted, without any escaping

bytes: byte type represents a data (byte stream) in bytes, the network transmission document storage and use bytes Type

 

Variable (Variable)

The amount of value can be changed, Python is a weakly typed programming language, variables need not defined or declared, directly to a variable assignment is to create the variable back you can use it directly, and its type can also dynamically change the variables the type depends on the type it was last assigned data

 

Common built-in functions (Built-in Function)

print: output data

input: Input data

type: get a type of data

Calculating the length of str, bytes, list, tuple, dict, set data such as: len

 

Spread

1. The way the two operating Python file

2.vim tips Editor:

In the line mode to display the line numbers set nu

set nonu to cancel the line number

In command mode by pressing p yy to copy

I want to duplicate rows to be copied by 4yy cursor line 4

3.Unicode Code: unified global coding, you can represent any letter symbols

4. Write code tips:

If the string contains a large number of single quotation marks, it may be coated on both sides of double quotes string

If the string contains a lot of double quotation marks, the string may be wrapped both in single quotes

You can reduce a lot of problems

Before the string plus r, i.e. in front of the quotes, it will literally when the word processing, do not escape

The data network can only be transferred byte by byte,

Guess you like

Origin www.cnblogs.com/yanruizhe/p/11203596.html