Learn Python - 1

in #python7 years ago (edited)

imageedit_2_9862275354.jpg
In this post I will show you how to start write python code and run them. If you are using a linux distribution then by default you will have python 2.7 but I prefer you to using python 3. Python 2.7 has 2 years and 1 month from now so It would be a bad choice if you start or continue with python 2.7.

One more thing, if you are familiar with compile based programming language you may be surprise at the beginning because python is an interpreter based programming language which means it directly executes what you write.

Lets fire up terminal(linux) or command prompt(windows) and then type python:

$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

As you see by default its python 2.7 so how we can start a shell or command prompt with python 3. If you have installed python 3 then:

$ python3
Python 3.6.3 (default, Oct  6 2017, 08:44:35) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Note

By default ubuntu comes with python 3.5 but as you see I use python 3.6 so If you want to install python 3.6 on ubuntu then check here install python3.6 on ubuntu.
Fow windows you need to go to python.org and install it. If you only have python 3 on your machine then you can just type python. Otherwise you have to specify as follows py -3

Its like a standard first print hello world to the screen. Lets do it:

$ python
...
>>> print('Hello, World')
Hello, World

This is the first interaction with python interpreter.
A word for print(): print is a function and It does print whatever you give as parameters. Functions are just like in math as you know from school. They can have input or maybe not and they produce an output. We will talk much more about functions, for now just know that print prints whatever you write between parentheses (something)

For the first this post is enough and I will make sure to not creates long post. So you would be able to read them on the bus, train or car for a few minutes. Thanks for reading.