Python 101: The Basics

TK
TK
Jun 15, 2017 · 3 min read

Part I: Variables, Control Flow and Looping

Image for post
Image for post

It is the first part of Beautiful Python series by Tk. We will talk about what Python is, a little about history and go deep to understand the basics of this beautiful programming language. Let’s start this conversation! :)

Introduction / History

Python is a “high-level programming language and its core design philosophy is all about code readability and a syntax which allows programmers to express concepts in a few lines of code” created by Guido van Rossum.

For me the first reason to learn Python was that it is, in fact, a beautiful programming language. It is really natural to code it and always express my thoughts.

Another reason is that we can coding in Python to multiple uses: data science, web development, machine learning shine here. Quora, Pinterest and Spotify use Python for their backend web development for example.

The Basics

1. Variables

You can think about variables as a word that stores a value. Simple as that.

In Python it is really easy to define a variable and set a value to it. Imagine you want to store number 1 in a variable called “one”. Let’s do it!

Wow! How simple was that? You just assigned the value 1 to “one” variable

And you can assign some value for whatever variable you want. “two” variable stores 2 integer and “some_number” stores 10000.

Besides integers, we can also use booleans (True / False), strings, float and so many other data types.

2. Control Flow: conditional statements

If” uses an expression to evaluate to True or False. If it is True, it executes what it is inside the if statement. For example:

2 is greater than 1, so the “print” code is executed.

The “else” statement will be executed if “if” expression is false.

1 is not greater than 2, so the code inside “else” will be executed.

You can also use “elif” statement. Like that:

3. Looping / Iterator

In Python we can iterate in different forms. I’ll talk about 2: while and for.

While Looping: while the statement is True, the code inside the block will be executed. So this code will print the number from 1 to 10.

The while loop needs a “loop condition” and if it keeps True, it continues iterating. In this example, when num is 11 the “loop condition” evaluate to False.

Another basic code to better understand it:

The “loop condition” is True so it keeps iterating, until we set it to False.

For Looping: you pass the variable “num” to the block and the “for” statement will iterate it for you. This code will print the same as “while” code: from 1 to 10.

Great! It is so simple! From a range starting with 1 until the 11th element (10 is the 11th element).

That’s it!

We learnt a lot of things about Python basics:

  • How Python variables work
  • How Python conditional statements work
  • How Python looping (while & for) work

And that’s it guys! I want to update this article. The idea is to share a great content and the community helps improve it! ☺

For the second part of this Python Series we are gonna talk about Python Data Structures.

If you want a complete Python course, learn more real-world coding skills and build projects, try One Month Python Bootcamp. See you there! ☺

Have fun, keep learning & always coding!

I hope you liked this content. Support my work on Ko-Fi

My Twitter & Github. ☺

The Renaissance Developer

Stories & Experiences from a Software Engineer

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store