#1 – Learn Python with practice – Introduction

#1 – Learn Python with practice – Introduction

Welcome to this first course about learning Python with practice.

Learning by practice will let you understand theory behind programming by yourself, you don’t  need teacher to become a programmer.

 

To start, you need some tools like in real life, we need everytime tools to build something. You will need here just Python installed in your computer, text editor and command line tool (Terminal in Linux OS or CMD on Windows OS).

Step #1 : download Python from here.

Step #2 : a text editor :

You can use a simple text editor like Note on Windows or Gedit on Linux but, I suggest you to download a text editor dedicated to write codes like Visual Studio Code, Sublime Text … etc. (some are 100% free).

One you downloaded and installed Python and a text editor, create now a folder named python-projects 

inside this folder, create another folder named intro

go to intro folder.

If you are on Windows, press SHIFT button on your keyboard (maintain it pressed) and right click then click on open command line.

 

If you are on Linux OS :

look for a program named Terminal then change your directory to intro folder.

 

Now, you will right your first code :

open your text editor and then open Intro folder that  you created. From your text editor create a file named main.py

copy and paste the following code in main.py file that you created:

# print text
print("Welcome to Python programming")

# ask user for his name
print("What is your name ?")
user_name = input()

# meet the user
print("Nice to meet you ", user_name)

go now to your command line (CMD or Terminal) and check if you are in intro folder, then write the following command :

$ python main.py

Note : the symbol « $ » marks the begining of a line code in your terminal, so just right python main.py

You should see in your terminal something like this in your terminal 🙂 :

Let’s explain what this code do line by line :

first line was # print text.

when you write the symbol # in the beginning of the line, you tell the Python interpretor that that line is a command and not an instruction of Python. I.e, it’s comment. Comments are used to write documentation inside the code.

Documentation helps developers to understand each others when they work together in the same projects.

In resume, lines started by # symbol are not executed.

Next line : print(« Welcome to Python programming »)

this instruction lets you print the text « Welcome to Python programming « , change Welcome to Python programming to whatever you want exept (« ) then execute python main.py command in your terminal again, you should see the output was changed.

user_name = input()

there is two instructions in this line :

user_name is a variable that can save data and use them later.

input is a function that ask user to write something.

user_name = input() means that the user input will be saved in user_name variable.

print(« Nice to meet you « , user_name)

What is this instruction ?

It print Nice to meet you and followed by the user input.


You learned meany things Déjà ! Keep learning, in the next chapter, we will talk more about Variables, Input, Outputs

Exercice :

Write a program that ask user for his age then print something like :

Your age is : 20

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *