Python basics 101

If you already know programming and you want to learn python then this post is the right one for you!. And use PyCharm IDE it’s supercool.

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”

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 Python is used for data science, web development, machine learning etc. Quora, Pinterest, and Spotify use Python for their back-end.

Let’s start with hello world!.

print("Hello World")
OR
print('Hello World')

Multi-line comment and single line comment

'''
This is a multi-line comment
'''
# This is a single line comment!

Variable — A variable is a place to store values, Its name is like a label for that value. A variable name can contain letters, numbers, or _ but can’t start with a number There are 5 data types Numbers, Strings, List, Tuple, Dictionary You can store any of them in the same variable.

name = "Bruce"
print(name)
name = 15
print(name)

Arithmetic Operators — +, -, *, /, %, **, //.

** Exponential calculation

// Floor Division

print("5 + 2 =", 5+2)
print("5 - 2 =", 5-2)
print("5 * 2 =", 5*2)
print("5 / 2 =", 5/2)
print("5 % 2 =", 5%2)
print("5 ** 2 =", 5**2)
print("5 // 2 =", 5//2)
Output:
5 + 2 = 7
5 - 2 = 3
5 * 2 = 10
5 / 2 = 2.5
5 % 2 = 1
5 ** 2 = 25
5 // 2 = 2

Conditional Statements — The if, else and elif statements are used to perform different actions based off of conditions. Comparison Operators : ==, !=, >, <, >=, <=. The if statement will execute code if a condition is met. White space is used to group blocks of code in Python.

if age >= 21 :
print('You are old enough to drive a tractor trailer')
elif age >= 16:
print('You are old enough to drive a car')
else :
print('You are not old enough to drive')

Unlike other programming languages, Python uses white spaces to differentiate blocks of code, instead of braces or semi-colons;

if ((age >= 1) and (age <= 18)):
print("You get a birthday party")
elif (age == 21) or (age >= 65):
print("You get a birthday party")
elif not(age == 30):
print("You don't get a birthday party")
else:
print("You get a birthday party yeah")

Looping statements — 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.

num = 1                                      
while num <= 10:
print(num)
num += 1

For Looping: you pass the variable “num” to the block and the “for” statement will iterate it for you. Range performs the action 10 times 0–9.

for x in range(0, 10):
print(x , ' ', end="")
print('\n')

And that’s it for today, ill continue Python 101 in my next post where I will talk about more stuff and yes there are no semi-colons or braces in Python and that’s what makes it so easy to learn!.

Thank you for reading, hope you enjoyed it, let me know what do you think about it and don’t forget to like and share and do all those good stuff!.

Your’s truly,

Bharat Kulkarni

It’s My C.R.A.P (Season 2, Episode 15)