Python 3 Learning Notes

Source: Internet
Author: User

Python 3.6 operator
    • +-*/arithmetic% * * exponentiation
    • Used to divide evenly
String
    • strings are enclosed in single or double quotation marks.
    • A three-line quotation mark (either single or double quotes) represents a multiline string, and the end of the line plus a backslash indicates that the line break is not within the string.
    • + for connection string.
    • * Used for repeating strings.
    • Adjacent string constants are automatically concatenated.
    • The string has fragment (slice) syntax, but the string itself is immutable.
    • Fragment syntax subscript 0 points to the first element, and subscript-1 points to the last element.
>>> Print("""\abc\""") ABC>>> ' A ' * 3' AAA '>>> ' B ' ' A '' BA '>>> ' B ' + "a"' BA '>>> "ABCDE"[1:]' BCDE '>>> "ABCDE"[:4]' ABCD '>>> "ABCDE"[:]' ABCDE '>>> "ABCDE"[-3:]' CDE '
Listing (list)
    • List: A data structure with the same type but unlimited number of members.
    • The list uses a special syntax with brackets and commas.
    • + Connect two lists.
    • The list has fragment (slice) syntax and the list fragment is variable (can be replaced by assignment).
    • Fragment syntax subscript 0 points to the first element, and subscript-1 points to the last element.
>>>[1,2,3][1:][2,3]>>>[1,2,3][-2:][2,3]>>>A=[1,2,3,4]>>>a[2:]=[4,5,6]>>>a[1,2,4,5,6]>>>a[2:]=[]>>>a[1,2]
Statement
    • While statement
    • For statement (essentially foreach)
    • If ... else statement elif
    • Code blocks are represented by a colon-indented
    • Pass statement (empty statement)
    • Break Continue statement
    • Loop + Else statement (indicates that the loop ends normally without being break)
>>>  forNinch Range(2,Ten): forXinch Range(2, N):ifN%X== 0:Print(N,' equals 'X'*'N//X Break    Else:Print(N,' is a prime number ')2  isA prime number3  isA prime number4equals2 * 25  isA prime number6equals2 * 37  isA prime number8equals2 * 49equals3 * 3

Python 3 Learning Notes

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.