In this article, we will learn how to start learning Python and create the first “Hello World” application using Python.
Key points covered in this article are:
What is Python?
Python is high level, general-purpose, interpreted, Cross-Platform, Case Sensitive and Object-Oriented programming Language. Python is created by Guido van Rossum and first released in around 1991. It uses an Object-Oriented approach which makes the programmer to write clear, logical code for the projects. Python has become one of the most popular programming languages used in the world. It is easy to learn because its syntax is similar to the English language, uses the new line to complete the command and indentation to indicate a block of code. Python is derived from C, C++, Algol-68, Unix Shell and other scripting languages, etc. The latest version of the Python is Python 3.
Many large companies are using the Python language includes Google, YouTube, Netflix, NASA, etc. It is available open-source and available at free of cost. Python is used in Web Development, GUI Application, Scientific and Numeric Computing, Console based applications, Enterprise Application, Data Science and Machine Learning, etc.
Environment Setup:
Python can be installed in multiple ways in a system.
1. You can directly download the python from https://www.python.org/ official website (as shown in below image). I am downloading Python for Windows Operating System. Python is also available for Mac OS as well as Linux operating system.
On clicking download, a .exe package of size Around 25 M.B. is downloaded. Click on it to start the installation. Make sure to add Python 3.7 to the Path variable (You can also do it manually as well).
Open command prompt, and type python –version command to check the version of Python installed on the system.
Run the Python command line interpreter by typing Python in command prompt and press the enter key. Type Print Function which prints the given object on the Standard output device (Screen) or to the text stream file. For demonstration, I am passing “Hello World” in the print function.
Creating a python .py file: Open any Text Editor available in the system. For example, In windows, open Notepad. Write the simple print method and save it as MyFirstApp.py.
Now run the python command line interpreter with the script name (with ext.) and see the output in the command prompt.
Some of the Popular Text Editor available are:
1. Visual Studio Code
2. Sublime Text
3. Atom
4. Vim
Setting Up Visual Studio Code for the Python:
Go to https://code.visualstudio.com/ and download the Visual Code. As I am using the Windows operating system, I will download setup for Windows. Once downloaded, run the installer.
After successful installation, Launch the VS Code, and click on the Extension icon and search extension for python. Click on Install. Extension will help us in providing intelligence, code formatting, snippets and debugging, etc.
Now, open a folder where you want to save python code. Then Click on Add new file, give it a meaningful name and then write the python code in it. I have written a simple code for demonstration.
Click on Debug Icon and then Start debugging. As I have created a single python file, select the currently active python file as Debug Configuration. In case your application not started by clicking debug, you need to check the launch.json and settings.json file for the configuration related issues.
The output of the application will be visible in Terminal as well as in debug console.
To create a New Script in IDLE, Go to File Menu, and click on New File.
2. Python in Visual Studio:
Visual Studio 2017 and higher version support the Python Development. During Installation of the visual studio, select the Python Development Component. I have already installed Python Development Tool in my Visual Studio 2017 IDE. Let’s create a new Python Project (console application) as shown in the below image.
In order to demonstrate, I have added some code in PythonApp.py file. Click on run.
In Jupyter Notebook, you can add cells and, in each cell, you can write code or Markdown as per your need for the documentation purpose. You can execute the code by clicking on the run cell button. The notebook is saved with.ipynb extension. It can also be exported to HTML as well as PDF format as well.
Hope this article will help you in getting started with Python.
Thanks.
Key points covered in this article are:
- What is Python
- Installing Python (in windows)
- Installing and using Visual Studio Code for Python development
- Woking with IDLE
- Visual Studio for Python development
- Anaconda Distribution and Jupyter NoteBook
What is Python?
Python is high level, general-purpose, interpreted, Cross-Platform, Case Sensitive and Object-Oriented programming Language. Python is created by Guido van Rossum and first released in around 1991. It uses an Object-Oriented approach which makes the programmer to write clear, logical code for the projects. Python has become one of the most popular programming languages used in the world. It is easy to learn because its syntax is similar to the English language, uses the new line to complete the command and indentation to indicate a block of code. Python is derived from C, C++, Algol-68, Unix Shell and other scripting languages, etc. The latest version of the Python is Python 3.
Many large companies are using the Python language includes Google, YouTube, Netflix, NASA, etc. It is available open-source and available at free of cost. Python is used in Web Development, GUI Application, Scientific and Numeric Computing, Console based applications, Enterprise Application, Data Science and Machine Learning, etc.
Environment Setup:
Python can be installed in multiple ways in a system.
1. You can directly download the python from https://www.python.org/ official website (as shown in below image). I am downloading Python for Windows Operating System. Python is also available for Mac OS as well as Linux operating system.
On clicking download, a .exe package of size Around 25 M.B. is downloaded. Click on it to start the installation. Make sure to add Python 3.7 to the Path variable (You can also do it manually as well).
Open command prompt, and type python –version command to check the version of Python installed on the system.
Run the Python command line interpreter by typing Python in command prompt and press the enter key. Type Print Function which prints the given object on the Standard output device (Screen) or to the text stream file. For demonstration, I am passing “Hello World” in the print function.
Creating a python .py file: Open any Text Editor available in the system. For example, In windows, open Notepad. Write the simple print method and save it as MyFirstApp.py.
Now run the python command line interpreter with the script name (with ext.) and see the output in the command prompt.
Some of the Popular Text Editor available are:
1. Visual Studio Code
2. Sublime Text
3. Atom
4. Vim
Setting Up Visual Studio Code for the Python:
Go to https://code.visualstudio.com/ and download the Visual Code. As I am using the Windows operating system, I will download setup for Windows. Once downloaded, run the installer.
After successful installation, Launch the VS Code, and click on the Extension icon and search extension for python. Click on Install. Extension will help us in providing intelligence, code formatting, snippets and debugging, etc.
Now, open a folder where you want to save python code. Then Click on Add new file, give it a meaningful name and then write the python code in it. I have written a simple code for demonstration.
Click on Debug Icon and then Start debugging. As I have created a single python file, select the currently active python file as Debug Configuration. In case your application not started by clicking debug, you need to check the launch.json and settings.json file for the configuration related issues.
The output of the application will be visible in Terminal as well as in debug console.
Using IDE for the Development: There are several IDE’s available with the Python support. Some of them are listed below:
1. Visual Studio
2. PyCharm
3. Spyder
4. Thonny etc.
5. Idle
Idle: Python (in windows) comes with IDLE (Integrated Development and Learning Environment) IDE which can also be used for learning Purpose. Search IDLE in Start button search and launch it.
You can also execute the python statements directly just as we did in Python Shell Command prompt.1. Visual Studio
2. PyCharm
3. Spyder
4. Thonny etc.
5. Idle
Idle: Python (in windows) comes with IDLE (Integrated Development and Learning Environment) IDE which can also be used for learning Purpose. Search IDLE in Start button search and launch it.
To create a New Script in IDLE, Go to File Menu, and click on New File.
Type the python code in it and save it with .py extension.
Once the file is saved, click on Press F5 to run the module in the Python Shell. On a successful run, Idle will show output something like below.
2. Python in Visual Studio:
Visual Studio 2017 and higher version support the Python Development. During Installation of the visual studio, select the Python Development Component. I have already installed Python Development Tool in my Visual Studio 2017 IDE. Let’s create a new Python Project (console application) as shown in the below image.
3 Anaconda Distribution: You can also install Python by installing open source Anaconda Distribution (https://www.anaconda.com/distribution/) which makes easier to use Python for data science and machine learning on Windows, Linux and Mac OS X. Basically, Once downloaded, click on next and next buttons to install it. (Installation is very simple. During installation it will ask the location to install and also ask to add path environment variables just like we did during python installation)
Anaconda Distribution provides libraries and tools with python for data science, machine learning, deep learning, etc. out of the box. It includes core python language, 100+ python library, Spyder and pycharm which are IDE, and Jupyter Notebook, etc. Search Anaconda Navigator in the start menu and launch it.
Running the Jupyter Notebook: Open the Anaconda Navigator, and click on the Launch button in Jupyter Notebook tile.
Basically, it is a web (client-server based) application which runs on localhost on default port 8888. Its UI shows files and folders. You can create a new Jupyter notebook by clicking on New and selecting Python 3 option.Running the Jupyter Notebook: Open the Anaconda Navigator, and click on the Launch button in Jupyter Notebook tile.
In Jupyter Notebook, you can add cells and, in each cell, you can write code or Markdown as per your need for the documentation purpose. You can execute the code by clicking on the run cell button. The notebook is saved with.ipynb extension. It can also be exported to HTML as well as PDF format as well.
Hope this article will help you in getting started with Python.
Thanks.
fstfd
ReplyDelete