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.
- Don’t mix space and tab.
- Use 4 spaces for indentation.
- Leave 1 line after a function.
- 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.