Diving Into Python - Chapter 4

Hello guys.
This article is the fourth of this series. In this am providing the basics of Python scripts by comparing them with several other object oriented languages to present a clear view of Python and other languages.

Getting the Theme

For getting the theme of Python, kindly go through my previous articles,

Basics of Python

This article will take you through some of the basic parts of Python that will include these contents,
  • Writing Basic Python Snippet
  • Python | Identifiers
  • Python | Keywords
  • Python | Comments
  • Summary

Writing your First Script

Now, without taking any more time I will show you how easily you can write a Python Script without any problem.
I'll try to explain it by comparing (in terms of structure and statements) with some other, featured object oriented languages like C++, Java and C#, so let's go through it.
GoodBye World | C++
So, let's have a look at a basic program in C++.
  1. #include<iostream.h>  
  2. Int main()  
  3. {  
  4.     cout << “GoodBye World!”;  
GoodBye World
GoodBye World | Java
So, let's have a look at a basic program in Java.
  1. public class Main  
  2. {  
  3. public static void main(String[] args)  
  4. {  
  5.     System.out.println("GoodBye World!");  
  6. }  
  7. }
GoodBye World
GoodBye World | C#
So, let's have a look at a basic program in C#.
  1. using System;  
  2. public class Hello2  
  3. {  
  4. public static void Main()  
  5. {  
  6.     Console.WriteLine("GoodBye World!");  
  7.    }  
  8. }  
GoodBye World
GoodBye World | Python
Now, it's Python. Have a look:
  1. Print “GoodBye World!” 
GoodBye World
And it's still “GoodBye World” guys.

Pin Point

“Now, guys I don't think I need to write anything in theory, since all those four code snippets says it all. The choice is yours.”
Python | Identifiers
An identifiers, in general programming terms they can be defined as in the following, 
"A name that can be used for identifying a variable, function, class, object, name and so on in a program, is called an Identifier."
This same definition and concept applies also to Python.
Here are some basic details one needs to understand about Python identifiers (common),
  • Must start with upper case (A … Z) or lowercase (a … z) letters
  • It can be also start with an underscore "_" , followed by more letters
  • It can also be the combination of underscore and numbers

Pin Points

  • Since Python is a case sensitive programming language, "Abhishek" and "abhishek" are different things for it.
  • Python doen't allow you to use some special characters (@, #, $, %) in your identifier name.
  • Class names start with a uppercase letter followed by the lowercase.
Python | Keywords
A keyword, in general programming terms can be defined as, 
"These are reseved words that are already used in language for defining some special taks or functionalities and you can't use them as a constant or variable name in your code.
Let's quickly have a look at those.
And Assert Break
class Continue def
del elif else
except exec finally
for from hglobal
if import in
is lambda Not
or pass print
raise return try
while with yeild
Python | Comments

Single-Line Comments

I love C# and more than that the symbol "#", so guys if you are .Net developer and you also love that symbol, then trust me you won't miss that in Python because in Python a line that starts with a hash "#" is considered to be a comment by the Python interpreter.
So write comments and enjoy Python, write as much as you can but in a limit and trust me it will help you too. How? It will make your code more understandable, readable and it also considered as one of the guidelines of programming. So cheers.
Have a look at the following snippet.
# So let's Print Something- Comment 1
Print “A chunk of text!” # Print- Comment2

Multiline Comments

No worries, if you want a multiline comment in Python. You can easily do that using this structure:
Your comments go here…
For Example
This is my multiline comment in Python...
Print “A chunk of text!”


This fourth part was for making you comfortable with Python. That is why I made several comparisons above.

Guidelines from my Side

  • Do as much as code you can.
  • Code anything you want, the best way to learn
  • Don't just study things, try to learn them.
  • Work on your concepts
  • Work on the fundamentals of any technology or stuff you want to learn.
“Keep calm and code Python”.
I tried to make this an interesting and interactive article and I wish you guys do like that, meanwhile, if you have any suggestions then you are welcome.
Until the next part, keep sharing.

Similar Articles