Introduction to Python

Anmol Sharma
8 min readMar 1, 2021

--

Welcome to this Introductory Blog Post about one of the world’s most popular and exciting programming languages; Python. In our modern highly advanced internet age, even those with a remote interest in technology or Computer Science may have been exposed to the language or its name. But in case you haven’t heard of Python, it’s an integrated high-level, general-purpose programming language. It was created decades ago and has since then enjoyed a unique place in Software development community as simple yet powerful language capable of handling challenges from AI, Machine Learning, App development, Web Development to even gaming.

In this piece I will first begin by discussing some of the reasons why Python is so popular, as well as illustrating why the reader should learn python. Then I will start by providing the user with small syntaxial guide to serve as an “appetizer” if you will into Python code, this will be done by comparing and contrasting it with the Java Language. This I hope will provide the reader with a picture of some the details of the language as well allow them to see some of the foundational concepts of the language.

Behind Python’s Popularity

With a language as diverse and extensive as Python it is difficult to quantify all the Reasons why Python has gained the mainstay position which it has, but these are among the most prevalent;

1. Versatility: as already briefly noted Python is a language which has found its way into nearly every corner of the tech space. There are really only a few other languages which rival Python and all the areas it can cover. From AI, Machine Learning, App development, Web Development to gaming. Python can do it all.

2. Shorter learning curve and easier to use: Python is a language which designed with ease of use in mind, there are serval caveats which are baked into the language which reduces the amount code needed to be written to achieve an operation compared to another language like Java, C, C#.

3. Large Experienced Community: another excellent feature which goes along with learning python is incredible depth and size of its community. This community is one which has built over a long period of time so it easy to find any number of resources and solutions to any problem which you will encounter. These resources include various books, blogs videos and so on. Due to the versatile nature of the language its only fitting that there be incredible diversity in these resources, which cater to almost any kind of learning style, and to any kind of level of experience.

Is Python worth learning?

Software development is and has always been difficult subject to get a foot hold into, it can be very intimidating for new comers which are often scared away from even starting by complex terms and difficult logic. But python can be easy to pick up learn if you’ve never covered the topic before. But even if you’re a seasoned developer, python has many advantages, the foremost among them being employability. Learning this language can make you extremely employable, it is an excellent weapon to have in your arsenal when trying to build you career.

Moving from Java to Python

Now let us move into a more practical endeavor, in this part of the blog I am goanna start showing you some of thes bare bones and foundational concepts of the language. I believe this can best illustrated by comparing contrasting python with java. I believe this small guide help get a small glimpse of language in action. We start simple concepts like variables, and move into decision structures, data types like list and then finish with methods. (Remember this is only meant to illustrative, if you want to master these concepts, just seeing is not enough you will need to crave put you own path and practice them)

A few Considerations

Before we jump into it, I wanted to just provide some generals differences between Python and Java which are worth knowing.

· Python is a language which was designed primarily in mind with readability, reusability and ease of use. This mean thankfully certain code is cut down.

· Python is a loosely typed language while on the other Java is strongly typed. This simply means the at in Python there no need declares the data type of a particular variable, but in Java you have to declare it.

· Python executes line by line this means that code which you write will read and complied and executed in order in which you wrote it , keep this in mind when writing.

Basics: Variables

As we can see these are simple variables, the actual value of them in uniform across both languages. But the difference lies in a few simple syntax choices in their declaration. The most obvious difference is, as already explained there is no need to add datatypes in Python. But there are others like the semi-colon. In Java all lines must be terminated with them, but in Python they are optional. Another difference is that in Java double quotes indicated a String, a single quote indicates a char. In Python you can choose either, it makes no difference.

Decision Structures: If Statements

If statements are critical component to programming, there are essential to for us to be able to control the flow of the program. If statements in Python are exactly same as in Java but with only a few key Differences. In the programs show above the user selects a weight type, then enters their weight after which it is converter to pounds or kilos depending their entry. In Java the if statement requires the condition being test to surrounded by brackets, but in Python braces optional but instead the end of the condition must have a colon. Another difference runs across all of Python is the lack of brackets, in Java an if statement is separated form code by enclosing brackets, in Python there is only indentation from the previous line which indicates a new block, anything which falls in that block in enclosed until the indent ends.

Decision Structures: While Loop

As we can see the bulk of the code for both languages is the same there being only slight differences. In the programs shown above the user plays a little car where they can start stop and quit the game, and until user enters quit, the games will continue. The main differences are first the use brackets, the whole while loop is heled separate from the rest of the code in java. Once again in Python this done with use the indent at line 6 in the python code. Everything which is at that indent is part of the while loop. The last difference the while loop’s condition which like the if statement is not surrounded by parenthesis in python and ends with a colon.

Decision Structures: For Loop

Here are two very simple for which both perform the exact same function, they print a list of numbers 0 all through 4. Printing an increment from 0, five times. All I’m sure you will able to tell by now that the java once again wraps its condition in parenthesis, and the whole for loop in brackets. Where’s the Python does wrap it condition n in parenthesis and ends it with a semicolon, and of course uses indent to separates the inside the for loop not brackets. But I want to draw your attention to the incrementing processing itself. In java the for loop does it man with the “i++” which increment it form 0 to 1 and so on. But in Python the in range feature does the incrementing automatically.

Furthermore, here we can see that using the in feature we can cycle though a String much easier than in Java. In you need build out the full for loop in-order to access each index of the String.

Data Types: Lists

Lists are a Critical data storage tool, in many key programs they are the necessary building block data type which allows them to function effectively and efficiently. Python’s version for this data type is something called list. Java on the other hand primarily uses array list. In Python the declaration for this data type is simple and requires no special import, unlike in Java. It’s just simple [] brackets, in which you declare it’s items. Another greater feature of lists is that you can print them very simple, by placing the variable in the print() method. Unlike in Java where u need iterate over each index.

Methods

Lastly lets examine methods, as you can see in this very simple example both methods functionality is the exact same, they simply square a number and return it. Creating methods in Python as compared to Java is far easier, since they require no access modifiers.

Here is a link to my video : https://youtu.be/7BXLpiAxrmw

I hope this brief post has helped gain some knowledge which will help in future endeavors.

--

--