The embodiment of the invention provides a code writing method and device, an electronic device and a computer readable storage medium. The method comprises the following steps: obtaining informationinput by a user, based on the obtained information input by a user, searching first code information matched with the information input by the user, determining target first code information when a selection operation of the user for the searched first code information is detected, and inserting the target first code information or second code information containing the target first code information into a corresponding position to realize code writing. According to the embodiment of the invention, on one hand, the time and labor cost consumed by manual code writing are reduced, and on the other hand, the possibility limit of previously written codes by copying and pasting programmers is reduced, so that the time consumed by copying and pasting is reduced, the complexity of copying and pasting is reduced, and the user experience is improved.