An electronic lock compatible with left and right opening, comprising a lock body and a lock tongue seat, the lock body is provided with a switch knob for a user to turn to open and close the lock, a rotating shaft that is coaxially arranged to rotate synchronously is connected to the switch knob, and a lock tongue that can be extended/received and a first transmission assembly for driving the lock tongue to extend/retract are arranged on the lock tongue seat, wherein the first transmission assembly is provided with a first rotating member capable of forward/reverse rotation to drive the lock tongue to be extended/received, and the first rotating member is provided with a front and rear through inserting slot, which is configured for the rotating shaft to be inserted and connected therein, so that the first rotating member can rotate synchronously with the rotating shaft, wherein the rotating shaft can be inserted from a front end to a rear end of the inserting slot so that the lock tongue can be oriented to left, and can be inserted from the rear end to the front end of the inserting slot so that the lock tongue can be oriented to right, wherein a driven gear coaxially arranged with the switch knob and capable of forward/reverse rotation is drivingly connected in the lock body through a drive mechanism, wherein a circumferential transmission mechanism is arranged between the driven gear and the switch knob, so that the two can rotate synchronously after they rotate in place relative to each other, and the lock body is also provided with a sensing mechanism for sensing whether the driven gear rotates to a specific position, wherein the specific location is one or a plurality of individually identifiable ones.