Part I: Variables, Control Flow and Looping
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.
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).
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. ?