Python Tutorial

Python, a 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.

Python is open-sourced. It means 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 divided into two categories – interpreted languages and compiled languages.

Compiled languages are those (e.g., Java) where sourcecode is compiled into executable instructions beforehand. Later these complied instructions can be executed by the runtime environment.

Interpreted languages are when the intermediate compilation step is not applied, and we can directly feed source code to the runtime environment. Here, source code to machine code translation occurs simultaneously as the program is being executed.

This means, we can directly execute any source code written in Python without compiling it.

2. Python is Simple

Python was mainly developed to emphasize 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

We can use Python for rapid prototyping, or 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 a file with the extension (.py) and execute the file using 'python' command.

Let’s write our first Python file, called helloworld.pyIn any text editor.

print("Hello, World!")

Please save the file and execute it in the 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 helpful 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 – OrderedDict example
Python – Dictionary intersection
Python – Priority queue example

7.4. Miscellaneous

Python – Read and write CSV files
Python – httplib2 library

Happy Learning !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.