Python book of magic/01.What is Python
What is Python?Edit
This is probably the very first question you will be asking. Python is a programming language. A programming language is a language that help the user communicate with the machine. The machine itself understands only machine language which nothing more that a series of 0s and 1s, known as the binary format. Those 0s and 1s operate like switches with 0 being "off" and 1 being "on". Of course, coding in 0s and 1s are not ideal, so programming languages have been invented with the sole purpose of bringing coding as close to a natural (e.g. English) language as possible. For those that are curious how weird machine code really looks like my friend PKHG has posted a table bellow that shows the name of the command, the mnemonic that is a shorter name and the actual machine code in hexadecimal and binary (op-code) format.
Example Cosmac 1802 CPUEdit
Command Mnemonic Hexadecimal Op-code Load immediate LDI F8 1111 1000 Shift right SHR F6 1111 0110 Short branch BR 30 0011 0000 etc.
On my (PKHG) Cosmicos, I had to to fill memory bytes (really!) by pressing for each 1 a corresponding button, there where 8 for the op-codes and a button fill in the op-code!
First version had a total of 64 memory places, and could make a tune via good sequence of commands like you can see in the table and an ear-hearer.
So programming like this is not ideal. Programming languages that are close to machine code are known as "low level". Assembly is the only low level programming language, and while it can use some commands that make some sense like "MOV" for data movement, it's still very much machine (CPU) dependent in its syntax. High level languages move away from machine code and are more English like, such as Java , C, C++, C#, D, Objective C, and many more. Higher level languages are much closer to English, and they generally implement concepts that are not technical. They are not closely tied to the machine architecture. Some of the higher level languages are Visual Basic, Ruby, Runrev, and more.
Why use Python?Edit
Using Python offers the following advantages :
- Python is a highly readable language. It is easy to read and understand Python source code.
- Python is popular, with million of coders worldwide.
- Python is powerful, and used by demanding companies Like Google, YouTube, and NASA.
- Python is portable, so without changing a line of code, it runs on Windows, Linux, Mac, etc.
- Python is compact, meaning code can be much shorter and simpler compared to C /C++, Java, etc.
- Python is easy to debug because the source code is short and easy to understand.
Most importantly, Python is an excellent choice for absolute beginners. Visiting any programming forum or any user forum, when a poster asks "what language should I first learn", Python is by far the most recommended choice.
How to install Python?Edit
You don't have to worry about installing Python, as Blender comes with Python installed. Python is in a folder containing an executable, which is the Python interpreter, and the library of Python commands and functions. If you want to use Python without using Blender, you can get Python from the Python website.
What is an interpreter?Edit
As I said earlier your machine understands only machine code. That being said, a tool is required to convert Python commands to machine code. This where the interpreter comes in. It takes your Python module, reading it line by line, and converting any Python command to machine code, which then executes. The beauty of the interpreter is that you can execute code interactively one command at a time, thus really test what works and what does not, making it easy to debug code, find errors, mistakes, and test different approaches.