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