Introduction to Python Programming
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.
Python is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Web Development Domain. I will list down some of the key advantages of learning Python:
-
Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP.
-
Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write your programs.
-
Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that encapsulates code within objects.
-
Python is a Beginner's Language − Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games.
Python Programming Environment
Python is available on a wide variety of platforms including Linux and Mac OS X. Below are the detailed steps to install Python on Windows.
Windows Installation
- Download Python executable installer from Python Official Website (opens in a new tab).
- Run the installer.
- Add Python to PATH by selecting the checkbox.
- Click on Install Now.
- Python is installed successfully.
Python IDE
Python provides a lot of IDEs for writing code. Some of the popular IDEs are:
- PyCharm
- Jupyter Notebook
- Spyder
- Visual Studio Code
- Sublime Text
Python Syntax
Python was designed for readability, and has some similarities to the English language with influence from mathematics. Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.
Key features of Python
1. Platform Independence:
Python is platform-independent, which means that you can write a program on a Mac OS X, and run it on a Windows OS.
2. Object-Oriented Programming:
Python supports object-oriented programming (OOP). The OOP approach focuses on objects that represent data and methods. Python allows you to create classes and objects.
3. Rich Standard Library:
Python has a rich standard library that provides a wide range of modules and packages. These modules and packages are used for different purposes, such as regular expressions, documentation generation, unit testing, web browsers, threading, databases, CGI, email, XML, HTML, audio files, etc.
4. Memory Management:
Python has an automatic memory management system that manages the memory. When you create a variable, Python automatically allocates memory to the variable. When the variable is no longer needed, Python automatically deallocates the memory.
5. Extensible:
Python is an extensible language. You can write Python code in other languages like C++ and C. You can compile the code in C/C++ and use it in Python.
6. Embeddable:
Python can be embedded in C/C++ programs. This means that you can put Python code in C/C++ code. You can also put C/C++ code in Python code.
7. Interpreted Language:
Python is an interpreted language. This means that Python code is executed line by line. The Python interpreter reads the code line by line and executes it. If there is an error in the code, the interpreter stops the execution and shows an error message.
8. Dynamically Typed Language:
Python is a dynamically typed language. This means that you don't have to specify the data type of a variable when you create a variable. Python automatically assigns the data type to the variable based on the value assigned to the variable.
9. Extensive Libraries:
Python has a large number of libraries that provide a wide range of functionalities. These libraries are used for different purposes, such as data analysis, machine learning, web development, etc.
10. Open Source:
Python is an open-source language. This means that you can use Python without paying any license fee. You can also modify the source code of Python according to your requirements.
Python Indentation
Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.
if 5 > 2:
print("Five is greater than two!")
Five is greater than two!
Python Comments
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #
, and Python will render the rest
# This is a comment
print("Hello, World!")
Hello, World!
Resources
- Python Official Website (opens in a new tab)
- Python Documentation (opens in a new tab)
- Python Tutorials (opens in a new tab)
- Python Tutorial for Beginners (opens in a new tab)
- Python Tutorial for Beginners (opens in a new tab)