Hex: 0x123
Boolean operation: And, OR, NOT null: None Comment: #raw字符串不需要转义: R ' xxx ' multiline character: ' ' xxx ' ' multi-line character +raw string: R ' ' xxx ' Unicode character: U ' Chinese ' If the Chinese string encounters unicodedecodeerror in a Python environment, this is because there is a problem with the format saved by the. py file. You can add comments on the first line:#-*-Coding:utf-8-*-List:l = [A, B, c]list Add new element: L.pop (d), L.insert (0, D) List Delete element: L.pop (), L.pop (2) Tuple: Tuple once created, it cannot be modified: T = (A, b, c) single Tuple: t = (A,) for loop: for name in L: Dictionary dict: = {a:1, b:2, c:3} access Dict:d[key], D.get (key) Traverse dict:for key in d:set:s = Set ([ A, B, C, c]) = = Set ([A, B, c]) update Set:s.add (x), S.remove (x) define function: Def my_func (x): Returns multivalued: Return a, b defines default parameters: Def my_func (x = ' Hello ' '): Define a mutable parameter: DEF fn (*args): The variable parameter has an * number in front of the name and can pass in 0, one or more parameters to the variable parameter. Slice list: L[:3]l[::2]: The 3rd parameter indicates that the step distance is 2. The range () function creates a sequence: range (1, +) in Python, iterating over the element itself rather than the index of the element. Index iterations: Enumerate () function: L = [(1, a), (2, B), (3, C)] for index, value in enumerate (L):d The values () method for the ICT object: D.values () iterative di CT key and Value:for key, value in D.items ():p rint [x * x for x in range (0, 100)] string can be formatted with%: s = "%s%s"% (' hello ', ' world ') word The join () method of a string can be used to stitch a list into a string.
Getting Started with Python learning notes