The scaling down of switching media encounters high leakage current in the traditional oxide material based memristors, resulting in high power consumption of chips. Two-dimensional (2D) materials promise an ultimate device scaling down to atomic layer thickness. Herein, black phosphorus (BP) and its self-assembly phosphorous oxide (BP) memristors are constructed, which leverages the high on/off ratio operation of oxides and low leakage current of 2D materials with high performance. The memristors exhibit reproducible and reliable switching characteristics with the on/off ratio >107 and data retention >104 s. Depending on the high reproducibility, basic "AND" and "OR" gates have been constructed on flexible substrates. Moreover, on the basis of the symmetry and linearity of conductance in the devices, the neural network simulation for supervised learning presents an online learning accuracy of 91.4%. This work opens an avenue for future flexible electronics.