how to write python code in arduino
You don't. Arduino code is written in C/C++/assembly in the IDE and it is compiled / linked to an executable that you load in the Arduino.
Python requires an interpreter on the Arduino that can translate the python code to machine instructions. It might exist, you will have to do the research. But I suspect that most Arduinos don't have the memory to handle it.
There are some products that use microPython; Sparkfun and Adafruit are places where you can look for those boards.
DSMohan:
how to write python code in arduino
questions without applications might very well be X/Y Problems
one uses python to connect to an EXP8266 for OTA programming.
Can you offer your application ? or perceived need ?
Arduino is inherently c++ based. It is possible to run micropython on some higher spec micro controllers but it’s not “arduino”.
MicroPython developer's page: https://micropython.org/. This talks directly to their own board, but it's an open source project that has been ported to a number of boards.
Adafruit spin on microPython with enhanced support for their board products: Welcome To CircuitPython | Welcome to CircuitPython! | Adafruit Learning System