Python, popular programming language, was created by Guido van Rossum, and released in 1991. Python is considered to be one of the hottest skills to have among the most popular programming languages.
It is open-sourced i.e. we are free to install, use, and distribute, even for commercial purposes.
In this tutorial, we will learn about python basics and some advanced concepts.
1. Python is Interpreted
Programming languages are generally devided into two categories – interpreted languages and compiled languages.
Compiled languages are those (e.g. Java) where sourcecode is compiled using compiler into executable instructions beforehand. Later these complied instructions can be executed by the runtime environment.
Interpreted languages are those when the intermediate compilation step is not applied and source code can be directly fed to the runtime environment. Here, source code to machine code translation occurs at the same time as the program is being executed.
In means, any sourcecode written in python can be directly executed without compiling it.
2. Python is Simple
Python was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code.
As a rough measurement of simplicity based on available keywords in the language, Python 3 has 33 keywords, and Python 2 has 31. By contrast, C++ has 62, Java has 53 keywords.
Python syntax allows a clean structure that is easy to learn and easy to read.
3. Comparing with other languages
- Python uses new lines to complete a statement. In other programming languages, we often use semicolons or parentheses.
- Python relies on indentation, using whitespace, to define scopes e.g. loops, functions and classes. Other programming languages often use curly-brackets for this purpose.
4. Uses and Benefits
Python can be used for rapid prototyping, or for production-ready software development. The below list identifies a few popular usages of python.
- Python has a large and robust standard library and many useful modules to use for developing the applications. These modules helps us in adding the desired functionality without writing any more code.
- As python is an interpreted high-level programming language and it allows us to run the same code on multiple platforms without modifications.
- Python can be used to write applications in a procedural style, an object-orientated style or a functional style.
- Python has features like analyzing data and visualization, which helps in creating custom solutions for big data analysis, machine learning and artifical intelligence.
- Python is also used in robotics, web scraping, scripting, face detection, color detection ans 3D applications. We can use python to build console-based applications, audio-based applications, video-based applications, enterprise applications etc.
5. Installing Python
Today, most computers and operating systems are shipped with python, already installed. To check if python is already present in your machine, execute the below command.
$ python --version #prints Python 3.8.0
If the machine does not have python installed then we can download it for free from the following website: https://www.python.org/.
6. Write and execute python code
6.1. Python files
As mentioned earlier, python is an interpreted language so we can write the source code in file with extension (.py) and execute the file using 'python'
command.
Let’s write our first Python file, called helloworld.py
, in any text editor.
print("Hello, World!")
Save the file and execute it in command prompt or console.
$ python helloworld.py #prints Hello, World!
6.2. Inline code
Python code can be run in the command line, directly, and is often useful to test a short amount of code.
To get the python console, type in command 'python'
in OS console.
$ python Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello, World!") Hello, World!
7. Learning Python
7.1. Language Basics
Python – Installing in Sublime Editor
Python – Comments
Python – Variables
Python – Data Types
Python – Keywords
Python – Keywords
Python – Integers
Python – Strings
Python – Lists
Python – Tuples
7.2. Strings
Python – String split() example
Python – String startswith() example
Python – String endswith() example
7.3. Collections
Python – Finding max and min in list or array
Python – Find largest N (top N) or smallest N items
Python – Unpack tuple into variables
Python – Tuples comparison
Python – Lists vs Tuples
Python – Unpack tuple – too many values to unpack
Python – Multidict example
Python – OrderedDict example
Python – Dictionary intersection
Python – Priority queue example
7.4. Miscellaneous
Python – Read and write CSV files
Python – httplib2 library
Drop me your questions related to python in comments.
Happy Learning !!