Hey guys, I'm back with some interesting topics to cover on our Python journey.
Learning anything can be difficult, right? Indeed, we need to learn to achieve our career goals. Okay, it’s fine; anyhow, we need to learn the skill at any cost. Then only will we be valuable in this vast competition. But how many of you agree that learning anything is easy if we find the correct path?
Yes, it is. Everyone's learning abilities are different, someone can learn by reading books or watching YouTube, while someone else learns more by explaining to others what they have learned. I choose this last option because not only me, but many people remember things better by explaining instead of just reading and memorizing. I'm not saying everyone needs to follow this; I'm just saying everyone has the ability to learn in their own way.
Today, we'll cover installation, syntax, the first program, and comments.
Let's begin with installation
Yes, everyone knows how to install Python, but let me wind up by explaining how we do it… No lengthy process, just open Chrome or any browser and search for "Python download"😂. Yes, guys, that’s it… Then we have options to download according to the system requirements. After the download, we know what the process is like... setting up the Python environment without reading the policies or anything, simply by clicking next, next, next, install, and finish. Ta-da…..
Syntax
I mentioned “RUN”. Now what we need to run. Simple, anything we want……But there’s a speed breaker to run anything. To run the thing firstly, we need to know “How to run the thing”. Here, that’s what we call SYNTAX.
Every programming language has its own syntax. Our Python also has its own syntax. We can run or print any statements with the " print " keyword in Python. In further articles, we will cover every syntax that we require to learn.
First Program
Do you know, guys, if anyone has started learning any programming language… their first program running in the compiler? Yes… It’s “Hello World!”
We also run the same here.
But guys, do you wanna know about who's the person who wrote hello world? Let me share that information too…
"Hello, World!" program handwritten in the C language and signed by Brian Kernighan.
We can run as many statements by using the print keyword. And it’s our first stepping stone to the success of completing our journey.
print("Hello World!")
One more syntax we need to learn about is indentation.
Indentation is nothing but giving a tab space or 4 spaces in front of the starting line whenever it requires usually. We can give any number of spaces, but we need to maintain the same number of spaces for the entire block.
Giving unnecessary indentation will also raise errors. So be careful while writing the code.
# The "." below indicates space.
Example 1:
....print("Hello World!") ❌
print("Hello World!") 🟢
Example 2:
for i in range(3):
print(i) ❌
for i in range(3):
....print(i) 🟢
Example 3:
for i in range(2):
...print("Hello")
....print("World") ❌
for i in range(2):
....print("Hello")
....print("World") 🟢
If we make any mistakes in providing the correct indentation, the error appears as follows.
ERROR:
File "/home/main.py", line 1
print("Hello World")
IndentationError: unexpected indent
Comments
Let me think! 🤔….. How to explain comments clearly… Anyhow, it’s not that much of a bothering concept, but it is useful.
A comment is nothing but a non-executable statement that describes what’s the intention of the statement or block of code.
It means it's like a traffic sign while moving on a road. It describes what we are going to cross. It's just an explanation of what we are running, that’s it. Always remember, “A comment should always be short and sweet ”… no need to describe the entire matter, just a simple statement to understand is enough.
Single-line comments
Single-line comment is represented with #. By keeping # in front of the line, it will become a comment. If we want to write many single-line comments, we can put # in front of every line.
#printing "hello world" print("Hello World!") #Firstline prints "A" #Secondline print "B" print("A") print("B")
Multiple-line comments
Multiple lines of comments mean we can follow either single comments line by line, or we use quotation marks without assigning them to any variable. Like we can use either ‘ or “ or ‘’’ quotation marks. The matter between them will be treated as comments only.
'''This is a comment ''' print ("Comment")
Conclusion
Finally, we've come to the end of this article. We have covered the basic topics of introduction. We will cover and explore more in further articles. Hope you will understand the concepts through this.