I choose Python because of one reason: It’s simple. At first, I tried to learn C++ because it seemed that everyone around me knows C++. But I soon realized that a language that has many rules, such as ending a line with “;”, is not suitable for me, who never coded before.
The more I learned Python, the more I feel that I can fly with it. Its simplicity allows me to do many things. Well, coding in some ways is about creativity, isn’t it?
Okay, no more blah blah blah. For whatever reason you chose, you should want to start right away. Let’s cut to the chase.
Those are my best friends. You can choose your best friends of your own, but you should be aware that Python 2 and Python 3 are not always the same. Please make sure that the things you got from the internet are suitable for your Python version.
You can code Python right there on your browser without installing it (Let’s try PythonAnywhere). But sooner or later, you will need an installed version.
To tell you the truth, I have no idea about the system either. But I’m used to installing things so this process is no longer painful. I’ll use a I-have-no-idea-how-these-things-work-underneath-my-computer language to explain the installing process.
First, you’re gonna download Python from Python download page. Click Downloads and choose Python version that suits you. There, my friends, you will have to make a choice for your own life: Python 2 or Python 3. Actually, I know they’re different, but don’t know what difference is in particular. But, you know, new is sometimes better, so I choose Python 3 (which is in form of Python3.x.x) .
After downloading, follow the installation instructions, which are a series of Next, Next, Next (you should choose the recommended options). Then, boom! You got Python installed. Easy, right?
There are 2 ways to run Python. The basic one is to run in interactive mode, which means you “talk” directly with the interpreter (note that it’s the interpreter, not the computer itself).
After you installed Python, you’ll see a little program called IDLE on you Desktop. You open that program, a line started with “>>>” will bump into your eyes. You can write your code right here, and an output (if any) will be returned right away.
Writing in that way is called interactive mode.
The other way is more common, called script mode. You write your code in a text editor, modify it as many times as you want, then save it with the extension
.py. To run the code, you only need to click on the .py file you’ve created before.
Or you can run the .py file (or even install Python) using Terminal (MacOS) or Command Prompt (Windows). But this method is kinda hard to remember, so I’m not gonna mention here. In case you want to know, check out this page or this page.
Now you have Python installed. You can bump into coding right away. But please calm down, you need to know some more information before actually writing your own code.
What is a program?
You probably heard the word "program" a lot. But are you sure that you already know what it means? I'd thought that I know, until I heard some questions asking about the differences between "program" and "software". (Wait, aren't these the same thing?, you might ask).
Well, to be short,
A program is a sequence of instructions that specifies how to perform a computation.
It's like a command to the computer, asking it to do something for you.
How about the software? I'm not gonna go into details because I don't have much confedence when it comes to terminology. But what I know for sure is that a software can consist of many programs. Or, in short, a program is a bit like the basis of a software.
50 shades of errors
You cannot avoid errors, even in real world. In programming, there are 3 types of error, or bug, you need to know.
Syntax relates to the structure of a program and any rules to keep that structure. It is similar to writing, where you need to ending a sentence with a right puntuation mark. Although human beings can sometimes understand a sentence without a dot at the end, programming languages do not. If you miss a ";" at the end of a C++ line, your compiler fails to understand and it will complain you right away.
Runtime error is a type of error that does not come into light until you run the program. It is also called exception.
This kind of error is sometimes hard to detect. If your program has semantic errors, it means that your program still runs sucessfully, but it does not do the right thing.
For example, if you use a comma to group 3 digits of a number, say
1,000. The program will make no complaints, but it will not understand it is one-thousand as the way you want it to understand.
Syntax rules relate to 2 things: token and structure.
Token is the basic element of the language, such as words, numbers, parentheses, commas, and so on.
Structure is the way the tokens are arranged. For example, when you are not using parentheses in pair (opening but not closing), or when you end a line code with
Lines and Indentation
See the code below
if x>y: print(x) else: print(y)
Why I need to start the
This is not the end. There are still so many things in the Python world that you're gonna learn along the way.