Python basic Syntax-2
First, the Python programming style
1. Syntax Requirements:
(1) Indent unity: "Common error: Indentation error"
-->windows in the tab 4, Linux 8, but the display of the same length, not easy to distinguish.
A. Settings-Preferences-tab settings-tick Replace with spaces
B. View-display symbol-Show spaces and tabs
(2) Variables:
A. First character: letter, underline
B. Other parts: letters, underscores, numbers
C. Case-sensitive
2. Data type
(1) Number type:
A. Integral type: Boolean, long-shaped (L), standard integer
B. Non-integral: double-precision floating-point, plural, decimal
(2) Sequence type:
A. String (str)
B. Tuple (tuple)
C. Lists (list)
(3) Dictionary
(4) Collection type:
A. mutable set
B. Immutable collections
3. Operation:
+-*/Arithmetic by digital logic
Eg:2**32:2 32-Time Square
The remainder of the 10%2:10/2
4. Comments:
(1) Single-line Comment: #
(2) Multi-line Comment "" or "" "" ""
Second, user interaction
1, Import module Imports "in the current folder"
(1) from sys import argv: Import the argv from the SYS module
(2) Import a as B: Name a B
(3) Import Sys,os,tab: Import multiple modules
(4) Python default find file path: "Find from start to finish"
2, user input: Raw_input ("") read into the default string
(1) References:
(2) Formatted output
(3) Terminal output highlighting: \033[32;1m%s \033[0m
32: Green word; 31: Red word; 42: Green background ...
(4) Length judgment print len ()
A. Enter is not length
B. Space calculation length
(5) Go to space:. Strip () remove the opening and closing spaces of the input, but do not remove the middle space
Eg:name=raw_input (' Your Name: '). Strip ()
Third, circulation
1. For
(1) Showing 1-100
(2) Length
(3) from 1-100, each number interval 2 (odd)
(4) Count to 5 display text
2, continue, break
3. While
Python basic Syntax-2