Python Programming for Beginners- Visual Studio Code Integration



Python is described as a high level programming language, operating some distance away from machine code structures. The syntax is easy to understand and use, making it a great first language to learn with very extensive integration capabilities and its ability to work across any framework such as web, games, executables and even data analytics, data visualization and robotics.


Python is a scripting language that is interpreted at runtime, meaning the code is read line by line, eliminating the need for resource hungry compilers as you would require in languages such as C and C++. Running codes line by line means any errors in the syntax or code will only be flagged when the program executes that line unlike compilers, where the error will be flagged before the program is executed.

                            Installing Python Program

Head over to https://www.python.org/ and access downloads. If you have a 64-bit system, it is advisable to install this instead of the 32-bit version as you may experience program crashes while using some higher functionalities. Browse through and download the latest version bearing in mind that new versions of Python 2 are still being released, codes of which not compatible with the latest Python 3.

Once you have downloaded the installer, launch it and select to install for all users, ensuring you change the install directory to C:\Python\Python37 and click Next till the installation progresses to finish.




The installation should complete in a few minutes with notification of special thanks to Mark Hammond, the windows expert who worked so hard and shared his knowledge to make Python for Windows evolve from the DOS platform.



Click Start > All Programs > Locate Python 3.7 folder and inspect the components you have just installed.

              Setting an Environment Variable for Python
Part of the configuration for Python programming involves setting up an environment variable. To do this, you need to copy the installation path where the program was installed C:\Python\Python37

Navigate Advanced system settings > Advanced tab in System Properties > Environment Variables > System Variables > Highlight Path > New > Variable name: Path > Variable value: C:\YourInstallationPath > OK and exit. 


Test your configuration works, launch command prompt (cmd) and call the program by typing Python. The version of the python code editor should appear to write your first program print (“Hello World”)




 Working with Integrated Development Environments (IDE)

Writing code in Python requires tools known as Integrated Development Environments, which interprets the command we type into the console. Many IDEs exist such as Eclipse and Visual Studio Code however, we can also use the default tool known as IDLE from our Python 3.7 installation.

In All Programs > Python > Select IDLE to launch the programming shell. You should see figure below;


Let’s go ahead and write our first program by printing ‘Hello World’ to screen.


      Getting to Grips with Syntax in Python Programming

Created by Guido van Rossum in 1991, Python has evolved to become very popular and can be used for the following;
- Web development (Server-side)
- System scripting
- Mathematics
- Software development

The language is so versatile and cross-platform, giving developers the ability to do the following;

- Create web applications on a server
- Connect to database systems to read and modify files
- Used alongside software to create workflows
- Handle big data and perform complex mathematics
- Rapid prototyping or production-ready software development

There are a few reasons why learning Python is a great idea. Among many others;

- Python is cross-platform and works on different operating systems like Windows, Linux, Mac and Raspberry Pi.
- Python has a simple syntax similar to the English Language.
- Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This makes prototyping very quick.
- Compared to other programming languages, Python allows developers to write programs with fewer lines of code.
- Python can be procedural, object-oriented or functional in its execution. 

Python was designed with readability in mind, and has similarities to the English language with some influence from mathematics. The language uses new lines to complete a command, as opposed to other programming languages like C++ that use semicolons or parentheses.

Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes, as opposed to other programming languages that use curly-brackets for this purpose.



        Installing Microsoft Visual Studio Code Editor

Microsoft have available an IDE called Visual Studio Code, which can be downloaded and used as an integrated development environment for Python programming, with support for numerous other languages like JavaScript, TypeScript, PHP, Azure, C++, C#, Docker and many more.

Its free and open source for Windows, Linux and Mac with integrated Git, debugging and numerous extensions available to install and configure.



1. Select and download the Visual Studio Code installer of your choice, launch and Click Next.


2. Check the radio button to add a shortcut to desktop, add VS Code installation to PATH and the folder path for the software files. Click next and install when ready.


3. The installation should complete after a few minutes and you may restart your computer.


Integrating Python 3.7 with Microsoft Visual Studio Code Editor

Once your VS Code program is launched, you will find five tabs to the left; Explorer lets you open folders and files to edit code, Search tab lets you lookup specific phrases and files, Source control tab can be used for Git integration or version controlling, Debug tab is used for running and troubleshooting any problems with your code and the final tab is used to install Extensions, a task we shall perform shortly to integrate Python with Visual Studio Code editor.

Click the extensions tab and search for Python to discover a host of results from various publishers.


Select the option published by Microsoft and install. Click Reload to relaunch the program with your new python extension.

From here, click VS Code explorer > create a folder on desktop called Python > create a new file named hello.py > proceed to write your ‘Hello World’ program, selecting your local python installation as the code interpreter. 


Select the option published by Microsoft and install. Click Reload to relaunch the program with your new python extension.

If you run into any errors, ensure that VS Code is set to use your current Python installation as an interpreter. Check the path for Settings.JSON if you run into debug errors trying to run your programs. 



                                               Final Thoughts

We hope you found this article useful for initial Python set-up, with Visual Studio Code integration to get you started on your programming journey. 

Further studies of syntax, file handling and managing SQL and Mongo databases will be explored in later lessons, focusing using Python for scripting and automation tasks to simplify server and network administrative tasks. Find more useful info here: https://www.w3schools.com/python/default.asp

Thank you for investing your time with us.



Credits organisations and development teams at Microsoft Corporation,Python.org and W3schools.com 

0 Comments:

Post a Comment