copy(Shallow and deep copy operations) copy — Shallow and deep copy operations — Python 3.7.4rc2 documentation copy — Shallow and deep copy operations Source code: Lib/copy.py Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed docs.python.org
import dis dis.dis('a = [1, 2, 3, 4]') """ 0 LOAD_CONST 0 (1) 2 LOAD_CONST 1 (2) 4 LOAD_CONST 2 (3) 6 LOAD_CONST 3 (4) 8 BUILD_LIST 4 10 STORE_NAME 0 (a) 12 LOAD_CONST 4 (None) 14 RETURN_VALUE """ dis(Disassembler for Python bytecode) dis — Disassembler for Python bytecode — Python 3.7.4rc2 documentation dis — Disassembler for Python bytecode Source code: Lib/dis.py The dis module supports the a..
import json data = { 'name': 'ACME', 'shares': 100, 'price': 542.23 } json_str = json.dumps(data) data = json.loads(json_str) # Writing JSON data with open('data.json', 'w') as f: json.dump(data, f) # Reading data back with open('data.json', 'r') as f: data = json.load(f) json.dumps(False) # 'false' d = {'a': True, 'b': 'Hello', 'c': None} json.dumps(d) # '{"b": "Hello", "C": null, "a": true}' s..
print(value, sep=' ', end='\n', file=sys.stdoutput, flush=False) with open('somefile.txt', 'wt') as f: print('hello world', file=f) Binary Data 읽고/쓰기 with open('somefile.bin', 'rb') as f: data = f.read() with open('somefile.bin', 'wb') as f: f.write(b'Hello World') t = "Hello World" t[0] # H for c in t: print(c) """ H e l l o """ b = b'Hello World' b[0] # 72 for c in b: print(c) """ 72 101 108 1..