Beginning with Python

The last blog was how to print any statement in python interpreter. As a programmer we want to store the output pf the programmer in the file. This can be done easily in python compared with other programming language. First create a file with a extension (.py)Then we want to change the mode of the file. This can be done with a keyword chmod.

$ chmod +x example.py

The + symbol is used to add the specific mode. x is used to execute the file. Similarly there are other two types r which is used to read the file and w which is used to write in the file.To execute this program just type

$ ./example.py

The output of the program is automatically printed

Indentation

Indentation is most important thing in the python. The indentation should be proper in the python so as to get the output else it will throw an error.

a=10

b=20

c=a+b

print(c)

When we execute this program, it will show an indentation error. While indenting don’t mix space and tab. Sometimes it may also throw an error. There are 4 rules which are used when we writing a program.

  1. Don’t mix space and tab.
  2. Use 4 spaces for indentation.
  3. Leave 1 line after a function.
  4. Leave 2 lines after a class.

Comments

This is used to define a code. This is achieved by using a symbol #. When we use this symbol the program after that symbol will not be executed.

a=10

b=20

c=a+b #This adds a and b and stores in the variable c.

print(c)

Modules

Modules are the inbuilt functions and variables which it can be reused. It always should have an extension .py. In order to use these modules we want to import it first. We can use the keyword import to import the function.

Introduction to Python

Python is the very simple language compared to any other language. It is simple and easy for coding as well as understanding. Python is used in all over the world and it also contributed in creating many apps,web development and so on.

What is Python

Python is a open source programming language which is very simple to understand. Generally python has no syntax like any other programming languages like java,c,c++ etc. Python has applications like web development, gaming, app development and other such applications. It is very easy in such a way that,if we write a program in c++ it will take almost 10-15 minutes but in python we can complete the program in a line.

Here is example to create a program to display hello world:

#include<iostream>

using namespace std;

main()

{

cout<<” Hello World “;

}

This the program in c++ to print Hello world. But in python we can print the string without any declaration or header file.

print “Hello World”

We can also create array in python. no= [1,3,4,2] is the declaration of array in python. We cal aslo perform some modifications like append, reverse, sort and so on.

Looping statements is also an important part in the python. The most commonly used loop are for and while

for i in range(1,5):

print i

This will prints the number from 1 to 4.Similarly the while loop is used when we don’t have the correct idea about the range.

Components

Even though the python is very simple to learn, it also has components like inheritance, class, functions and so on. In order to declare a function the keyword def followed by the function name. class is also declared with a keyword class and followed by the any class name. In python, one class can inherit the property of the other class.In class b(a) the derived class b inherits the property of the base class a.

File handling in python is very simple when we compared with the other operating system.

exam=” Get ready for the exam “

f=file(‘exam.txt’,’w’)

f.write(exam)

f.close()

This will store the contents of the exam in the form of file. The import thing is no semicolons should be used after the line likewise in other programming languages.

Basic commands in Lunix

Linux is the open source operating system. Many operating systems work on the basis of the Linux. But working with linux is lot easy as windows. There are some basic commands to work with linux.

1.pwd

This command used to check the current location of the file or diorectory.

2.mkdir

This command used to create a directory to store files.

3.vi

This is an editor which is used to create different file formats.

4.cp

This command is used to copy file from one directory to another.

5.rm

This command is used to delete the contents of the file as well as the file.

6.mv

This command is used to move file from one directory to another,

7.cat

This command is used to open a file.

8.cd

This command is uded to change directory. cd.. will come out of the directory.

These are some essential and basic commands which are commonly used in the linux,