Sign in
Log inSign up
Why Do I Use Python?

Why Do I Use Python?

Siddharth Rout's photo
Siddharth Rout
·Nov 15, 2020·

7 min read

Why Python?

One Line to Glory

Python is loved around the world for its efficiency, making it a great language for beginners and professionals alike. What needs 5 or 10 lines in a language like C++ or Java can be accomplished in just 1 in Python.

For example, I am going to create an array with all the even numbers from 0 to 50 in Python and Java.

my_arr = [ x for x in range(1, 51) if x % 2 == 0 ]

This is a popular technique of creating lists in Python known as list comprehension, and allows the creation of lists in only one line. Now, let me try to do the same thing in Java.

int[] my_arr = new int[25]

loc = 0

for (int x = 1; x <= 50; x++) {
  if (x % 2 == 0) {
    my_arr[loc] = x
    loc++;
  }
}

As you can see, the Java code to do the same task requires a lot more code, and this is non-inclusive of the class and method declarations. Python is beloved because tasks can be accomplished simply and quickly, making Python a more efficient language for a developer.

However, it is important to remember that different languages are suited for different purposes, and you should learn languages depending on what your aim is. As a starting language, though, Python is one of your best options.

As Simple As That

Python is also extremely simple to pick up as a beginner, with many of the operations involving English words. For example, below is an example of an if statement with an OR gate in both Python and C++.

if num % 2 == 0 or num > 10:
  print(num)

The if statement checks if a number is even or is greater than 10, and if so, prints the number out. Here is the same code in C++.

if ((num % 2 == 0) || (num > 10)) {
  cout << num;
}

It is extremely easy for someone who has never written a line of code in their life to look at the Python code and figure out what it does. However, with the C++ code, you would have to look at a resource to figure out what || or cout << does. This makes Python extremely easy to get a hang of, and once you have mastered it, switching to other languages is not very difficult.

Wait, I Can Make An AI?

Python has a vast array of packages which its users have created, which can do everything from create and train a machine learning model to order a pizza which reaches your door in 30 minutes or less. There are over 100,000 Python libraries, and you can create one without too much trouble. (All of these libraries are hosted on PyPi )

These packages, combined with a very active and helpful user-base, help immensely in your Python journey. While programming, creating a game, for example, there are many tasks that you have to do, such as choosing a random item from a list using a pseudo-random number generator. These tasks might not seem too complex from the top, but creating and generating a random item from a list from scratch is extremely difficult. Using a library such as the random library helps simplify this random choice into one line.

import random

my_list = [1, 2, 3, 4]
num = random.choice(my_list)
print(num)

random.choice(my_list) chooses a random item from my_list and returns it. Without libraries such as these, you would spend much more time coding minor parts of your solution, making most people bored. These libraries speed up parts of your solution so you can focus on the parts that matter to you.

Additionally, Python is a rapidly growing language, and it has a very supportive user base. The r/python and r/learnpython communities on Reddit are extremely helpful to programmers of all skill levels. In addition to this, if you have any problems, one quick search and you will find someone who has solved your problem on StackOverflow. It is extremely important to remember that programming is not about memorizing, rather, it is about trying to find the most efficient path to a solution. In the real world, StackOverflow is the most helpful tool for programmers.

Conclusion

I love Python! It is extremely simple and convenient for beginners, but it can get advanced very quickly, with topics such as decorators and different packages. If you want to get started with programming, I think that there is no better language to do it in than Python.

-----------

If you enjoyed this article, please share it with your friends, family, and anyone else you think will be interested in this! I am a small blogger, and I rely on your support to grow my blog. Thank you so much!

My name is Sid, and I post an article every few weeks on interesting topics related to IT, Computer Science, Science, and Mathematics! Thank you for reading SIDR!