Get Introduced To Python in 10minutes!
Python is the most trending and widely used object oriented programming language in the present world of development, created by Guido van Rossum in the 1980s. Python is designed to be a general purpose, high-level, interpreted programming language and is open source. One can download it easily from Python.org. This was a basic introduction to python and as we go deep into the article we will take a shallow dive into it. Get ready for an amazing python tour!
There are many other object and procedure oriented programming languages like C, C++,Java,C# and so on, but what makes python special is, it’s easy to use less complicated syntax which even amateur developers can learn very easily. When I first started learning python, I was amazed with the way how it’s syntax is designed. It gives more emphasis on natural English language and due to its ease of understanding and usage, it’s highly popular and even can be executed much faster when compared to any other programming language.
The most cute thing I noticed about python is the “traceback” it gives for compilation errors, it seemed to me as if python is not understanding my statements and is angry. Unlike other programming languages that tell it on a developer’s face as “syntax error”, python gives a traceback requesting its programmers to trace their mistakes and tell the statements more clearly. In my opinion traceback is the polite way of calling a syntax error or any other compilation error that a programming language throws at programmers. There is a beautiful trick to overcome the exasperation that one goes through while facing traceback especially after coding for hours, this usually happens with every programmer and has an easy way to handle it. Keep reading to know!
An amazing feature of python is that its programs can be easily converted to softwares, with the help of different libraries such as pyinstaller or py2exe and such. The main advantage behind this is, any python software consisting of an executable file can be magically executed even on computers with no python installed and reason for this is, python being an interpreted language, while conversion of python program to python executable software, the interpreter is incorporated into the same folder as where python executable file is placed, hence enabling it to be executed on devices with no python installed. Python programs are saved with extension .py and a simple command in CLI can convert this program to software, this helps developers convert their great codes to softwares in minutes. The different web scraping programs that I developed got converted into softwares within no time and were all up and running in a few blinks.
Python with its vast collection of libraries, supports web-backend development, game development and software development which all together have taken a common name as python development. I have seen my friends enjoying the oldest snake game that can be developed using python easily. Apart from this even different types of adventurous games can be developed using python.
Python even contributes to immensely popular technological fields like data science, artificial intelligence, machine learning, big data, cloud computing, open CV,deep learning and such with its libraries and frameworks such as numpy, tensorflow, django,flask beautiful soup,scipy and so on and all these libraries help a lot in initial cycle of development, saving a lot of time of the developers and with all these functionalities python has proved itself as the most powerful programming language in the world of development with many companies using it as their official programming language, Google is one such example.
I started learning python through an online specialization, my instructor Dr. Charles Russel Severance, always used to say a trick to handle the anguish mixed irritation a developer would get by seeing tracebacks, for that matter say, a compilation error pops up giving a traceback and we go mad at it, he used to say, to consider python an innocent baby snake that is angry at us as it didn’t understand what we just told it. This thought alone would bring a smile on my face whilst coding, instead of exasperation. Apart from this cute side, python even has a powerful side, with a potential to do various tasks as per developers interests, Let’s move on to that now.
Python has a good range of versions and first appeared 30 years ago, with its first version released in 1991. Python3 is considered to be the stable release of python with 3.8.0 being the latest release. For python releases 2.7.9 and 3.4 onwards pip, a python standard package manager is made available with python installation and is used for installing additional libraries that are not inbuilt standard libraries of python and can be installed using a simple CLI command as pip install library_name. For earlier versions of python, pip needs to be installed separately. My suggestion for any python beginner would be to dive into python 3.
Basics of Python
Python 3 and its updates, being the most stable releases of python are widely used by developers. Like any other programming language, python3 as well as other python versions provide loops, branching statements, functions, classes and use of variables for developers to code at an ease. We will be focusing on python 3 and its basic functionalities, most of which is similar to python 2. The print statement of python 2 has become a print function in python 3 and is written as print(“whatever to be printed”) for example:print(‘Hello world!’) and that ends our python 3 hello world, as simple as that. The raw_input() function of python2 has become only the input() function in python 3. In python 2, the implicit str type is ASCII and in python 3 its Unicode. Python even supports error handling with try/except code blocks where there are certain small but noticeable changes in these two versions of python. Apart from this they even differ in xrange() function and _future_ module
Python unlike some other programming languages doesn’t differentiate between characters and strings through their writing styles, for example “hello” and ‘hello’ both are considered as strings and ‘h’ is considered as a character because it’s a string with length 1. Hence python is smart enough to understand the difference between strings and characters and like many other popular programming languages strings in python are arrays and characters are strings with length 1. Even, there is no need to mention data types of variables in python as the interpreter understands it based on the value given to a particular variable. Now this in my opinion is highly convenient for any programmer and as for me, when I would code in c++, I would always forget to declare variables with its data types and end up getting compilation errors, but the python interpreter manages all of it magically.
Python variables even accept all types of integer and decimal values and even provides many standard library functions to operate on them such as ord(), str(), int(), Round(),float() and many more where these inbuilt functions operate on different types of variables.
Python even allows conditional branching with if, elif and else statements, where every line inside loops, functions and conditional statements of python must be indented and kept at the same indent level for the interpreter to understand which statement belongs to which block. If you miss an indent the baby snake is going to get very angry, so do remember!
In order to tell the interpreter that a block of code has come to an end, the next statement is unindented to the previous indent level of other blocks of code. For-loop in python is amazingly designed and is completely different from for-loop in many other programming languages. A single mentioning of the iteration variable would be enough to complete the loop and iterate till the end. For-loops easily make out the end of data structures like tuples,lists and dictionaries and there is no need of mentioning a separate ending condition.
Just like all other programming languages, python has its own data structures where lists are nothing but arrays and tuples are arrays with rounded braces. Dictionaries are little different where all the values are stored with keys referencing it, hence it follows keys as its index. Python even facilitates use of regular expressions that reduce both length of code and time taken by the programmer to code.
While loops are having true condition as default condition for entering the loop and terminating condition must be mentioned separately inside the body of the loop. In order to define a function in python, define keyword is used and when control encounters a function call it automatically shifts to body of the function and executes the statements there, though this sounds similar to execution flow of functions in other programming languages, there is a lot of difference in their syntaxes where unlike other programming languages functions in python doesn’t need to be mentioned with their data types but parameters if any, must be compulsorily mentioned, again without their respective data types. Python follows ‘#’ for single line commenting and multiline comment blocks are not supported hence consecutive single line commenting is followed to comment out multiple lines.
Python for a reason is termed as an object oriented programming language where it supports all the features of OOP, such as defining classes, polymorphism, encapsulation, inheritance and gives a greater emphasis on objects with class serving as a blueprint of the object and object as the instance of the class. For instance, objects can be people, cities, countries etc and usually are common nouns containing data like name, place,address,age etc. Definition of classes contain methods or functions and can be accessed through objects.
Python is the second most widely used programming language for data science after R. Python mainly finds its use in data science fields like machine learning, deep learning neural networks, big data, cloud computing and what not. It has made its place in almost all the popular fields and it’s knowledge is compulsory to enter the field of data science. I had learnt this amazing fact from one of the courses that google offered is that, Artificial intelligence is a sub field under computer science and Machine learning is the sub field of artificial intelligence, and is incorporating deep learning. Data Science for that matter has all of their applications in parts, making them its sub domains. Henceforth, python is spread across all of these fields, confiscating the entire computer science domain in its beauty and power.
Along with this python supports even database management with a python-mysql package that has a MySQLdb, OurSQL and so on modules that is actually written in C language. I kept on clapping for the python creator in my mind when I worked with this amazing package where python and mysql are combined to manage databases. Python even has a library sqlite, with the help of which a database file is generated by itself and the developer needs to just provide the name he wants to give to the database. This is compatible only with sqlite browser.
Python with all it’s amazing features and being the most efficient programming language is trending in the field of development and is expected to be the most widely used development language in the world of technology than now. This ends your python tour for now, but definitely is not the ending of python! as it gets even more amazing as one goes into its intricacies.