Sitemap

Python Series- Basics

3 min readMay 30, 2022

--

So in the last post, we learnt about python and downloaded PyCharm community editor. Today we will start with basics of Python.

Python Indentation

Indentation refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.

Python uses indentation to indicate a block of code.

Example

if 5 > 2:

print(“Five is greater than two!”)

Python will give you an error if you skip the indentation:

Example

Syntax Error:

if 5 > 2:

print(“Five is greater than two!”)

so basically indentation is the space left before the first word of the line like print(‘ python indentation’) now the space left before print is the indentation used here.

Python Comments

Comments are used to explain the code. basically you rough notes in the code that python ignores. comments always start with a hashtag #.

Press enter or click to view image in full size

Example

#This is a comment

Get Aarav Gupta’s stories in your inbox

Join Medium for free to get updates from this writer.

print(“Hello, World!”)

Comments can be placed at the end of a line, and Python will ignore the rest of the line:

Example

print(“Hello, World!”) #This is a comment

A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:

Example

#print(“Hello, World!”)

print(“Cheers, Mate!”)

Python Variables

Variables are containers to store data in them. so if you assign a value, it will save it in the container. take the example of amazon. it has so many usernames, how does it remembers each and every one of it. All through the power of variables.

Creating Variables

Python has no command for declaring a variable.

A variable is created the moment you first assign a value to it.

Press enter or click to view image in full size

Example

x = 5

y = “John”

print(x)

print(y)

Python is a case sensitive language. so if you type a = “ I am learning python”

print(A) then python will give you a error because a is small in the line 1 and caps in the line 2.

Press enter or click to view image in full size

We will start with data types in the next post of this series.

--

--

Aarav Gupta
Aarav Gupta

Written by Aarav Gupta

Decoding AI Engineering through practical deep dives into LLMs, Agentic AI, RAG, cloud architecture and intelligent systems.