A Newbie Guide to Python
New to Python? Here's a breakdown of the basics, including a history of the language, who uses it, and Python 2 vs 3 differences.
Join the DZone community and get the full member experience.Join For Free
Python is a programming language that is useful for writing quick and simple scripts, but it is also a good language to use for creating large-scale full-blown applications. Even massive operations like YouTube use Python to deliver their content over the Web. Python is easy to learn for beginners while at the same time being sophisticated enough for experienced engineers to use. Let’s take a look at Python’s features and history and explore the reasons to use it.
What Is Python?
Python is a high-level, object-oriented programming language. It is an interpreted language, which means that you do not need to compile your programs before running them, speeding up the cycle of writing code and debugging it. Python is a versatile and widely used language, so many standard Python packages are available for you to use when writing your code, rather than having to write every algorithm from scratch.
A Brief History of Python
Python was created in the late 1980s by Guido van Rossum. Van Rossum had already worked on a language called ABC, which was Python’s predecessor. Building on his earlier work with ABC, van Rossum created a simple parser and virtual machine, then started to develop the basic syntax of Python. He named the new language after Monty Python’s Flying Circus, a popular British sketch comedy that he enjoyed.
Guido van Rossum released the first version of Python in 1991. He continued to be the chief author of the language for many years, although other people have also contributed to the language’s development.
Python 2.0 was released in October 2000, with several significant improvements, including support for Unicode and a full garbage collector to get rid of variables that are no longer in use by the program. The latest major Python release is Python 3.0, which includes many simplifications compared to Python 2.0 and is designed to help programmers do things in the easiest and most obvious way.
How Is Python Different From Other Languages?
Python versus Java/C++
Python is considered easier to get started with than Java and C++, which are also object-oriented programming languages. Python uses dynamic typing, which means that programmers do not need to spend time defining their variables before they use them. As a result, Python code is usually 3-5 times shorter than Java code that serves the same purpose. The comparison against C++ is even more favorable; Python code can be up to 10 times shorter than the equivalent code in C++.
Python Versus Perl
Python is often used as an alternative to Perl, which is another scripting language that allows programmers to quickly write useful code. However, Python is designed to be much easier to read than Perl, allowing programmers to efficiently share, debug and maintain code. On the other hand, Perl has a lot of useful features for application-oriented tasks, such as built-in regular expressions.
Advantages of Python
Python is often considered to be one of the best languages for introducing beginners to programming. In fact, 80 percent of the top computer science departments teach Python in their introductory programming courses. It is widely thought to have one of the most shallow learning curves of all programming languages, making it an excellent choice for new programmers.
Python is written to be read. It has a simple syntax that closely mimics English. It also uses white space rather than curly braces to identify function bodies, forcing new programmers to lay out their code in a standardized and easy-to-read way.
Python code is very brief compared to some other languages. You do not need to define variables at the beginning of the program file, as the interpreter handles typing when you run the program. This is one less thing for new programmers to think about when they are learning to code for the first time.
Huge Range of Packages
As well as being a great language for beginners, Python is also very useful for experienced programmers. It is the fifth most commonly used language on GitHub. Python’s popularity means many people are developing packages for the language. Python.org keeps a list of the most popular Python modules, packages and libraries that can help programmers to visualize data, manipulate images, and develop interactive websites.
PIP stands for Python Package Index. It is a tool that you can use to quickly and easily install Python packages. Simply use the commands ‘pip install’ and ‘pip uninstall’ to add and remove packages. PIP downloads packages before installing them, preventing partially completed installations.
Python is an interpreted language. There is no compilation step between writing the code and running it. This speeds up the process of writing, testing and fixing the code, which is an attractive feature for many developers.
Finally, Python is completely free, which gives it an advantage over a few competitors. For example, scientists can use Python as an alternative to proprietary languages like Matlab for data analysis and simulations.
Disadvantages of Python
Python has a few drawbacks, which can make it unsuitable for some applications.
Python runs more slowly than many other languages. This is due to it being an interpreted language. In compiled languages, the compiler can create code that runs quickly and efficiently. Therefore, Python is slower than compiled languages, such as C or C++. There are variants of Python, specifically designed to handle certain situations, which can run faster.
Python 2 Versus Python 3
Newcomers to Python must choose whether they want to program in Python 2.7 or Python 3. Although Python 3 is the most up-to-date version of the language, some programmers are reluctant to make the switch as many useful libraries are not yet available for Python 3. While the availability of two stable versions of Python is not necessarily a significant disadvantage, many new programmers are confused by the choice. Python 2 and 3 have similar syntax, but they are not entirely compatible, so you need to be aware that two versions exist and check that all the packages you want to use are available for your chosen version before you start your coding project.
Who Uses Python?
Python is a very versatile language. As a result, it has a very wide variety of applications. Python is used for web development, including the development of online games. Python also has business and financial applications.
Scientists are some of the primary users of Python. This fast and easy scripting language allows researchers to analyze quickly large amounts of data. Climate scientists, bioinformaticians and geneticists who need to handle vast quantities of data often find Python very useful.
Some companies and websites that use Python are very well-known. For example, Yahoo Maps relies on Four11, an application whose address and mapping lookup services are written in Python. Yahoo Groups was also initially implemented in Python, and the language still underlies much of the functionality of this site.
Python has tremendous applications in the gaming industry. For example, Eve Online (a space-based MMORPG) makes extensive use of Python on both the client side and the server side. Running an MMPORG requires a powerful language that can efficiently manage resources. Eve Online uses StacklessPython, a variant of Python that can handle thousands of tiny tasks.
In September 2015, 0.2 percent of the world’s websites used Python. That might not sound like a lot, but the proportion of sites in the top million that use Python is twice as high. Out of the Quantcast top-ranked 10,000 sites, 43 of them use Python, a slight increase since 2014. The majority of these sites are using Python 2.6, not the latest version.
Here are some other major websites currently using Python:
- Web Therapy
- Google (some elements of the Google search engine are written in Python)
- Linux Weekly News
If you want to learn to program in Python, or you want to find out more about the history and development of the language, then Python.org is a great starting place. You can download whichever version of the language you want to use from this site, whether that is the latest release of Python 3 or Python 2.x. This site also has an extensive catalog of resources for learning Python.
Learning to program in Python is a good choice if you are new to programming. If you are an experienced programmer, then adding Python to your list of skills could also be a smart move for your productivity and career. Python is widely used in a range of industries and has important applications in web development.
Published at DZone with permission of , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.