Getting Started with Python

 Print   6 min read  
02 Sep 2022
Beginner
2.77K Views

Python is a dynamic, interpreted, easy to learn, readable high-level programming language. It was created in 1991 by Guido van Rossum. It is a versatile programming language and allows you to do many things, both big and small. Python is being used in different areas like Machine learning, Data analysis, Web Development, Automation and many more. If you are beginner in programming, then python suits for your career.

Features of Python

  1. Dynamic Typing

    Python doesn’t have something like type declaration of variable, it automatically tracks the objects when your program runs.

  2. No Manual Memory Management

    Python uses garbage collector rather than manual memory management. It allocates and reclaims (“garbage collects”) memory from objects according to their use and most can grow and shrink on demand.

  3. Essential object types

    Python provides basic data structures such as list, dictionaries tuples, and string as essential part of language and they are versatile and easy to use.

  4. Useful Packages

    Python has large collection of packages for different purpose and has great support in community. Python has packages for everything searching, sorting, data analysis, web development, machine learning, socket programming, NLP and many more.

  5. Programming-in-large-support

    Python includes tools such as class, modules, and exceptions. These tools enable you to modularize your system and use OOP to reuse and use your logic in code for customization, handle events and errors.

Advantages of python

  1. Large Support

    Python has strong support that makes it applicable for the development of larger system, and it has packages for almost everything that can be used easily.

  2. Readable

    Python is more readable than many other languages like Perl. It has clear and simple syntax, that helps to reduce program bugs.

  3. Easy to Learn

    Python code is very simpler when you compare a code written in python with equivalent code in C++ and also lesser almost one-fifth of C++.

  4. Mixable

    Python can be easily “glued” to modules written in another language. Python programs can be called and other programs can also be called in python.

  5. It's Portable

    The standard implementation of python is written in portable ANSI C, and it compiles and run on virtually every major available platform.

Setting Up Machine

For windows first go to https://python.org in Downloads section you can see all latest version of python available for windows. We will be using python 3.7.0. Download the setup and run.

Once installed we will setup Python path in Environment Variables.

  1. Right click on My PC and click on properties.

  2. In opened window choose Advance System Settings. Below you can see Environment Variables click on that.

  3. Add new variable in your System variable section.

    • Variable name: PYTHON_HOME

    • Variable value: C:\Users\UserName\AppData\Local\Programs\Python\Python37;

  4. Select PATH variable and click on edit

  5. At the end of PATH variable add: - %PYTHON_HOME%

  6. Verify path setting – Just open command prompt and type python and you will see the prompt.

    For Linux and Mac user python comes pre-installed in both the Operating Systems you can just execute python3 command on terminal to check.

Now setting up IDE for Python. We will be using Visual Code for Python.Download and install Visual Code Here and also Install Python Extension.To install Python Extension:

  • Click on View tab and select Extensions.

  • In search box search for Python and you will find the extension.

  • Install it and done.

Sample Program

We will write a very basic program to add two numbers in python.

  • Open the Visual Studio and click on New File.

  • At the bottom right you will find a button to select language mode by default it will be Plain change it to Python.

  • Now write the below code for adding two numbers:

 
 # This program adds two numbers
 
 num1 = 1.5
 num2 = 6.9
 
 #Adding numbers logic
sum = num1 + num2
 
 #Display output with formatting
 print('The sum of {0} and {1} is {2}'. format(num1, num2, sum))

Running Program

  • Save your file with .pyc extension.

  • Click on View tab and open Terminal.

  • Execute command.> python yourfilename.py

  • You will see the below output on your screen.

After the execution of your program you will see another file is created with extension

".pyc". It’s bytecode file or compiled code file which is usually created in the same directory as the ‘. py’ file. From the above example, we can see it’s very easy to learn and use language so go ahead and explore more.

Program Explanation

  • ‘#’ is used to type comments in python

  • The next line follows the declaration and initialization of the variables you can see we didn’t mention the type of the variable python dynamically understands the type from the value we assign to variable.

  • In next line we are assigning the sum value of both the numbers in third number.

  • At the end we formatted our output. Python gives different formatting syntax’s this syntax you can relate with C++ style.

  • We gave the values which we want to get replaced with ‘{0}’ and respectively in format ()

  • Python is an interpreter language so if you make any mistake in program your execution will stop at that line.

Summary

Python is used widely by many organizations like Google, Quora, Nasa and many more. In the above article, we gave an intro about Python, its features and how you can start with Python. Python is a very popular language and you would easily find many tutorials to get started and learn.

Learn to Crack Your Technical Interview

Accept cookies & close this