General way of writing python program
For writing a piece of code in Python
Open a text editor (preferably use atom or sublime Text or VS_Code or jupyter notebook)
You can always use python interpreter or Python shell that can be directly used in python IDLE or in Terminal It is recommended just to use for checking one or two lines of code or in case you want to view the working of loop and want to get help
python IDLE opens like this:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin Type "copyright", "credits" or "license()" for more information. >>> print("Hello World") Hello World >>>
Terminal : You just need to type python3 and it will open like this (The exact texts may vary)
ADITYAs-MacBook-Air:c aditya$ python3 Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
Writing Code
You can use/copy sample.py file and create new file, edit in that and save that with different names
Running python code
Open Terminal Goto the directory using 'cd' command type ADITYAs-MacBook-Air:python aditya$ python3 sample.py //In my case sample.py is a filename to be run
Books/References for studying Python
> Feel free to contribute