Introduction To Python Basics

 

Introduction To Python Basics

 


Developed by Guido van Rossum in 1991,  Python is a high-level programming language. This general-purpose language is prevalent in almost all domains, be it web development, game development, software development, data analytics, AI, and ML. Its flexibility and portability make it a popular language for many industries and top companies like Netflix, Google, and Facebook.

Let’s explore some of its essential features in detail below.

Features Of Python Programming Language

·         Readable: It is an easily readable language.

·         Cross-platform: Python can run on any operating systems be it Windows, Mac, Linux, Unix, etc. This quality makes it portable and cross-platform.

·         Simple to learn: As it is a high-level and expressive language, it is easy to understand and learn.

·         Open-Source: It is an open-source programming language, which means it is free to download and use. Similarly, you can distribute copies of its software, read the source code and modify it.

·         Large standard library: It comes with an extensive standard library that provides handy functions and codes, useful while writing code in Python.

·         Supports exception handling: It supports exception handling, which makes it less error-prone and can be tested in various scenarios that can cause an exception.

·         Automatic memory management: It supports automatic memory management, meaning the memory is freed and cleared automatically.

·         Advanced features: Supports list comprehensions and generators.

Introduction To Python Basics

Simple Hello World Program is the traditional way of starting, and every developer knows about it. Simple Hello World Program is the very first line of code you should begin with to learn any programming language.

Getting started

You will need a Python interpreter and a graphical editor to run Python programs. The Python interpreter helps execute Python code, sometimes known as programs. There can be one or more python files in a program, while code files include other modules and files. When executing Python, you need to specify a parameter to run a program.

Run Python code

Next, get a Python interpreter installed. Open a terminal and launch to run the code.

Python file.py

Python IDE

An IDE is a development environment that you can use if you don’t want to work from the terminal. In this graphical editor, you can type code, work with various files, run code, and many other things.

Most IDEs have a structure where you will see a file menu, the code, main menu, line numbering, scrollbar, files and program output, and additional information.

If you are not a terminal expert, IDEs can save tremendous development time. You can work with multiple files and people on one project and switch between projects and work. PyCharm, Wing IDE, and PyDev are some popular Python IDEs.

Execute Python scripts

Execute Python scripts in an IDE or the terminal. As Python files have the .py extension, save the Python script as name.py whenever you make it.

#!/usr/bin/env python3

print(
'hello world')

A simple program (hello.py) is shown here. The first line indicates you want to use the Python interpreter. The last line outputs a line of text “hello world” to the screen.

The text can be copied into a text editor and saved as hello.py. Python works with files that have a .py extension.

Any text editor will work to create a Python program. However, a text editor that supports line numbers and syntax highlighting (text coloring) is better.

Run Python

Run from terminal

You can run a Python program with the terminal or command line. And, it works on all platforms such as Windows, Mac OS Linux.

Press Windows + R key (run program), type command or cmd, and then press ‘Enter’ to open a terminal on Windows:

On Mac OS, use the finder to start a terminal. You can press command+space and type terminal, then press ‘Enter.’

Start program

To start the python program, you will need to open the command line and type:

python hello.py

To make this work, you’ll have to be in the correct directory meaning the directory where your program is located.

You can see the current directory on Linux and Mac OS using the command pwd.

The directory is visible in the command line title bra in Windows.

Use the command ‘cd’ to change the directory like this ‘cd /home/user/pythonprojects’ or ‘cd C:\Projects\.’

Run from IDE

In order to run a Python script from an IDE, you need to start a project first. After the project is created, add your .py files (or make them in the IDE) and press run.

In the PyCharm IDE:

·         Start project

·         When the welcome screen opens, click on Create New Project.

·         Go to the main menu, choose File | New Project.

·         Choose Python interpreter

·         Select Python version from the list. Use 3. x

·         Click create

·         Add new Python file and add hello.py

·         Click on the green triangle to begin the program. You can do it by right click on your Python file and select Run.

Other IDEs work the same way and have a similar process to run a Python program: start project, add a file, and run button.

Output

Finally, you will see a line of text displaying “hello world.”

Conclusion

Once you have mastered the “Hello World” program in Python, your next step should be to master concepts like variables, data types and data structures, conditionals and loops, OOP. Make sure you have a strong hold on the basic concepts before moving to the advanced concepts like Tkinter, Plotting, PyQt, Flask, Pandas, etc. 


 

 

 

 

 

Comments

Popular posts from this blog

30 Minutes AWS Interview Test in US

Trend of Python in the Last Few Years

Java Coding Technology School & Bootcamps