#Python101

Introducing to Python!

Hi, it’s Dominika here and I’m very pleased to meet you in “#python101” section. On this page you can find some important information for beginners.

1. How to install a Python on your computer?
2. Introducing to IDE’s of Python.
3. First code: step by step.
a. Playing with Variables
b. Showing text on screen
c. Numbers! (we do love numbers)

1. How to install a Python on your computer?

First thing to do is to install program to your laptop or computer. You can choose a lot of programs: Spyder, Jupyter Notebook, Visual Studio Code, but I would recommend you Anaconda, because it is a platform where you can choose your favorite editor. Also, in Anaconda you can also program in another language, for example in R.

Anaconda is an open-source platform which has everything you need to have to start programming Python. Furthermore, lot of free tools that you can use in more advanced projects, for example for data analysis or science. This is because Python is really easy and universal language, so you can write simple programs or very advance ones. We start with simple programs!


If you click the video, you will see the easiest way to install it or if you want to install it by yourself, use this page.

For writing our very first code we will use “Spyder”. Click it on Anaconda!

2. Introduction to IDE’s of Python.

In this point, I will be talking about Spyder’s layout.

This is how it looks when you start it for the first time.

On the top of the screen you can find the main menu. It looks very similar to other programs. First two icons are about creating new Python file (it has .py extension) and opening saved file. Next two icons are about saving your work. When you click on the forth icon you can switch between files very quickly and the next one is symbol searching icon. Then you can find icons which allow you to run the program (you can also click F5 on your keyboard). If you find any bugs in your program, you should use third section which is all about debug.

On the right site you can find File Editor. But you can configure the window as wish, so you can put some other widow there.

The main is just a Python code editor. In this section we will write the code!

3. First code: step by step.

Let’s start programming! I will show you something really simple!

a. Playing with Variables

This is the simplest thing that you can do in any programming language and of course Python as well. Take a lot how I done it!

Why do we need Variables?
A Variable can store text or number or some object for you. If you would like to display Hello World, you need to declare a Variable for the Hello World string and use print function.
If you would like to store the number of games your favorite basketball team has played this season, you could do it by declaring the games Variable.
If you would like to know how many baskets the team has shot per game, you could store the value in the avg_score.
The good thing is that Python takes care about data types, so you do not need to think about it during coding. For example, the games Variable should be a type of integer because it stores the number of games. However the avg_score Variable is rather decimal than integer.
If you would like to know the type of your Variable then you should use the type function.

But I can tell you even more about it! The same Variable can be use for different data types. For example, the games Variable can store integer value, but if you assign a Hello World text to it, it will be a type of string. However, this is not a good practice.

b. Showing text on screen

Showing text on the screen.

c. Numbers!

The difference between string variable and a variable that store number is that on numbers you can do math. For example, you can add points, number of people that attended in the game or number of fouls committed by players. However, you can not do this operations on strings.

Let’s start with naming the variables. I will do example with two basketball teams and their scores. First team scored 105 points and the second got 89 points. I named the variables as you see on the picture below.

Then I have calculated the difference between these two scores. I just subtract two variables and create a new variable called score_diff for the result.

I’ve done like I explained in “showing the text” point (use “print” function to see the result).

I’ve ran it and took a look on the IPython Console where the results have shown.

The answer is 16!

You can also do other operations on numbers like: addition, multiplication, division and many more you know from school. Python has a lot of libraries that help you in more advanced math. I will tell you more about this in separate course.

Summary

This is it for today! Now, you should be familiar with how to start playing with Python. I hope you like it.
If you like it, share it on twitter with #codingfamilynet!