Learn Basic Python Programming EP.1.

p1.png


I think people should just start learning programming, everyone basically. You know the human brain is wonderful, but it's very limited, and if you want to do complex calculations or searches or just comparing,testing, analyzing something, then your brain is no match to a Dual Core processor that they sell these days.

It's faster and definitely more reliable than your bad memory or your inability to pay attention to things for long. So learning to speak to the computer is probably one of the best skills a person can have in the 21 century.


Learn Python


Let's learn Python, which is a very easy to learn language, best to use on Linux machines, but I believe it can be installed on Windows and Mac too. In this tutorial we will use Linux.

The language can be very powerful, and I am not expert in it, but I can easily teach you the basics here, just so that you can do some basic calculations.

First of all it's totally free , under Python Software Foundation License, like GNU/GPL, so you don't need to beg for permission like a slave from your corporate overlords to use the code in your own projects. You can essentially do almost everything you want in it.

It's 100% free, and it is already included in most Linux Distro's, so if you were to install Linux Mint right now, you can just have access to all of the free softwares there, including Python.

Python is the language, not the editor software, and there are many editor softwares that offer fancy editing experience like Visual Studio for C++, but none of that is needed for a novice.

You can literally just write the code inside the text editor, that is what I am doing, it's just so easy that your mind will be blown.




Intro

So just open your text editor (gedit) it's essentially like Notepad in Windows but it has a better GUI and more customizable.

Then save the text file like test.py, where .py is the Python extension. Actually the extension is not even needed, unless you turn the file executable, which is only needed for complex projects, but we will just run the script from the terminal, whatever. If you don't name the file with the .py extension, then put this as the first row of the file #!/usr/local/bin/Python in order for the editor to know that we are programming in Python, and it will highlight the keywords as such. We will just go with the extension, it's simpler.

1.png

You run this script by opening the terminal and writing Python test.py, the Python command calls the Python software and it executes the file given. You can essentially run Python from the terminal, or code in the terminal, but it's easier from a text file that you can save.




Hello World

The first example is a hello world, where we make the script return us hello world. To display text inside the terminal, because we will be using the terminal, the print command is used. Anything after the print is printed out.

If there are multiple arguments, then use ( ) brackets to separate them, like multiple variables, otherwise for simple text output we use " or ', essentially if you have a quote where the " is part of the text, then use ' to wrap around it.

It looks like this:

2.png

And when we run it, it prints out our text.

3.png

If you have a quote, then we use the ' to wrap around the quote:

M1.png

Looks like this:

m2.png

So if you have to use quote marks " inside the text, or we call it string, then ' shall be used as external wrappers.

You can just enter print multiple times, each time in new row, to print out an empty line. I will actually use it like this, so that I don't have to edit out my username from the terminal in the screenshots.

T1.png

Or more elegantly using the \n newline operator, with 1 print call:

T3.png

You can also add a comment inside the code,which will not be read by the script, it's just there to explain to the reader what specific parts of the code do, like some stickers on your fridge.

The 1 line comment operator is # the multiline operator is ''' which must be closed. Essentially the multiline operator can be used to insert a license inside your code, while the single line operator is just a 1 line comment:

t4.png

None of the comments is displayed when the script is executed, as I said, it's just for the programmer:

T5.png




That's it for the first episode, now you know how to display text in the terminal. It's nothing useful yet, but learning to use the print function is essential since this is the only way you can communicate with yourself from the terminal.

So make sure you understand how the print command works, and test it out yourself. It's the first step to learn programming in Python.


Sources:
https://pixabay.com
Python is a trademark of the Python Software Foundation


Upvote, ReSteem & bluebutton


Sort:  

Good tutorial buddy... Python is really useful for data analytics and data mining... And the syntax is too simple.. I really love python 😊

Indeed it is, it's very easy to work inside the terminal ,especially for oldschool people like me. I used to do C++ on Windows before this and the software always crashed after putting it to analyze markets for too long.

Python is less resource intensive in the terminal and it's very efficient. Multitasking is also pretty easy to do.

Yup 😊 I was using c,,, after that cpp. I learned python for fun and fell in love with it. The syntax specially

Too simple? Let's say simple enough. ;)

He he 😊 yes buddy.. Agree with you 👍

upvited , restimed followed :)))

Amazing info thanx for sharing

I wish you a happy day

I suggest you go through the trouble of installing Python 3.6 if you are following this series. Python always releases very complete libraries with its interpreter. So for learning, you might as well start from what is the most current.

https://steemit.com/programming/@leprechaun/why-you-should-use-python-3-6

Isn't it python 2.7 included in distros, or have they updated all the OS scripts to use python 3 ? I haven't looked at this for a while.

Both 2.7 and above are simultaneously included, most of the time the 3.x ones are updated to the latest version, but I dont always upgrade to the latest, mostly to the stable version, wheezy I belive it's nicknamed, to not accidentally break a chain of package dependencies.

So you are on Debian, I liked to use some packages in testing (Squeeze ?)
but some stuff it is much better to use the stable version.

I'm just starting to learn Python.
Need to set up the software in my laptop soon.
Following because I like the tutorials <3
Thank you.

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.031
BTC 60840.29
ETH 2577.70
USDT 1.00
SBD 2.57