In this lesson i'll show you how to install, setup and write your first line of code in Python.
Head to the official site and in the upper left side you'll see Downloads tab. Select your operating system (e.g. Windows) and make sure you download the latest version.
Run the installer and once the prompt window appears, make sure you check "Add Python to PATH"before continuing. This move add the interpreter in your execution path. You can do this separate, but why to get things complicated?
Now, juck click "Install Now".
So, the instalation process just finished and you are not sure if it's installed or not?
Well, here comes the easy part: press "win key + r" and type "cmd". A black window will appear and here will be your first interaction with Python. Don't worry, you are not forced to learn Python programming in this sad black window ( only if you want to). Python has built in an interpreted, called IDLE where you can code or you can use an external interpreter ( recommended).
I the black window, type "python" and hit enter. This will show you the version installed and you are ready now to write your first Python code.
"Interpreted" it's a new word for you? Well, now you are ready for your first lines of code.
Type" 2+2 " and hit enter. Surprised? This is what Python do! Not wasting time like other programming languages to compile. This makes is simple to use and understand.
Now, try to type and enter "hello". Not working, aa? :P This is because it's interpreted as a string and must be declared. I'll talk about this later.
So i said earlier about your first code or program in Python.
Well, the most important function in Python, is the " print " function. You'll use this 90% of time. This will show you what you want to express in your code.
As in many programming languages the first program in called "Hello World", i'll name our first line of code " Hello Publish0x" :P
- A big difference you must count, the whitespaces. Python doesn't care about whitespaces, you can have as many as you want in your code, as long as they are not at the beginning at the code. For example, "space 1+1" won't work, will give you an indentation error. In Python, whitespaces matters only at the beginning of the code. Python uses 4 spaces to organize code in code blocks. This makes it easier to use, read and debug.
So, the print function. To print, you must declare something in parantheses.
print(1+1) - 0,1,2,3,4,5... are integers, words are strings. Strings are marked with " ".
print(Hello Publish0x) - what, error? well, Strings are marked with " ".
Congrats, you just wrote your first Python line of code!
See you in the next lesson,