Python basic Syntax-2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.