Python context

PYTHON:

Python is an interpreted, object oriented, high level programming language with dynamic semantics.. Python supports modules and packages which helps to reuse code (by calling particular module). Python is highly popular in usage of  AI, MACHINE LEARNING, DEEP LEARNING and API etc..

Python is one of the easiest programming language to learn. Anyone can learn python easily without programming background. Python is also very famous for simple programming syntax, as like normal English .


In this post, i am trying to explain some Python basics and definitions which, can help you to get some basic stuff of python context.

Variable: 

Variable is a reserved memory location to store values (numbers, strings..).

Rules for creating variable:

  •  A variable name must be start with a letter or the underscore character.
  • A variable name cannot start with number.
  • A variable name can only contain  alpha-numeric character and underscore (A-z, 0-9, _)
 Example: x=100, Name=Rajesh, Age=25 

Indentation: 

Python uses indentation to highlight the blocks of code, by simply using some space,  while in other programming languages we generally use brackets.

 Example:
   if 5>2:
      print(' five is greater than two')

As  you can see there is blank space in second line i.e indentation.

Indexing:

Indexing in python is a way to refer the individual items and we can fetch them. In python objects are zero-indexed meaning the position count starts with zero.

Example:

 Names= ['Rajesh', 'Ram', 'Krishna']  
       
                  [    0            1           2       ] ⇐ here index numbers
                  [   -3           -2          -1     ] ⇐ we can use negative numbers also in reverse direction

Slicing:

Slicing used to returns a portion of elements in a string, list...by using indexing we perform this slicing method.

Example: 

Names[0:]  ⇐ gives all names Rajesh, Ram, Krishna
Names[0]   ⇐ gives only first name i.e Rajesh.
Names[-1]  ⇐ gives only last name i.e Krishna or (you can use Names[2] )
Names[0:2] ⇐ gives 0,1 indexes i.e Rajesh, Ram


Error:

The most common reason of an error in a python program is when a certain statement is not in accordance with the prescribed usage. There are several errors in python, like syntax error, index error, key error, and ModuleNotFound error etc..

 Python Module:

Any text file with the .py extension containing Python code is basically a module. If the programming algorithm requires defining lot of functions and classes, they are logically organized in module. One module stores different python objects such as functions, classes, variables, constants, etc,. Such a modular structure of the code makes it easy to understand, use and maintain.

We can create our own module as per requirement and there are some modules also available like math, random and etc,.

Syntax:

from math import sqrt, factorial  (to import specific functions from module)

from math import *   (to import whole module)

Module Attributes:

A module is described by its attributes. The attributes of a module perform some tasks contain some information. 

Ex:

__name__Attribute:

Packages:

We  organize a large number of files in different folders and subfolders based on some criteria, so that we can find and manage them easily. In the same way, Package. Physically a package is actually a folder containing one or more module files.

As you know, module contains multiple objects, such as classes, functions, etc. A package can contain one or more relevant modules. 



Comments