Learn Programming in Python From Scratch Getting Started

By @ai-enthusiast11/10/2017science

Everyone can, and should learn programming. This is why I'm doing this posts.

Firstly we need IDE (Integrated Development Environment ), which we will use to write and execute our code. There are many choices, however I've found out Spyder, works best, 'cause it comes with pre-installed libraries.
Visit : https://www.anaconda.com/download/
Choose your OS (Operating System), and download Python 3.6 version.
Installation is standard, nothing special, just like any program, so I'm not including photos.
After Installation, search for Spyder on your computer, start it, and you'll be presented with a screen like this:
screen.png
Start a new project by going Projects>New Project. Give it a name (anything you want).
In project explorer tab, right click on a project folder and select New>Module. Give it a name you like.
In the middle of the screen you have tab, named Editor. This is where you type your code. On the right, you have a console, this is where your code gets executed. To start executing. Press the Play Button. That's all you need to know for now.

After that, we can get started with Python.

Comments:

Comments are essential to programming, as they give perspective, about the code being run. To declare a comment
you start a line with #, and everything you write after it in the line will we ignored by compiler.

Primitive types:

In Python, you have couple of primitive types that are built into language:
Integers (whole numbers), Floats (decimal numbers), Booleans(True or False, used for conditionals), Strings(arrays of characters), Lists(ordered gathering of elements), Sets(unordered gathering of elements), Dictionaries(key-value pairs).
examples of them:
Types.png
Special attention should be given to lists, sets, and dictionaries.
Lists:
Elements of a list can be of any type, you can have even heterogeneous list(in which not all elements have the same type). You can nest lists inside other lists. To access the elements of a list you type the name of the list followed with brackets, and an index of the element needed. (Indices start from 0, meaning the index of the first element is 0). Same goes for strings. You can think of them as deprecated lists of characters.
list indexing.png
Sets:
Elements of a set are unique to the set, it cannot be, that two elements are the same in set. That can happen only with lists. You cannot index a set.
Dictionaries:
Keys of a dictionary are unique, while the values can be same for two different keys. Keys and values can be of any type.

Constants vs. Variables:

Variables as it's name suggests changes over time. More specifically, It's associated Value is being changed during time.
To declare a Variable you start a line with it's name, followed by =, and you give it a value.
Vars.png
Constants in Python do not really exist, after declaring a Variable, you have to watch as to not change it's value.

Conversions:
After giving a variable it's value, obviously you can change it. But not only that, you can change it's type as well:
conversions.png

Operators:

Operators are needed to make the code intuitive and simple. There are math and logical operators
operators.png

That's it for the first post :D

77

comments