Python is general purpose high level, interpreted, object oriented programming language. there is initially invented by Guido van Rossum in 1991.
There are lot of feature are support in python programming. here given few with small overview. there are as following
Keywords: This language are provide few keywords, easy to memorized those keyword and learning its concepts.
Python 2.7.12 keywords
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
Python 3.5.2 keywords
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
If you are use other version of python. then find out number of keywords using this program.
import keyword #display keywords print(keyword.kwlist)
This function are print the number of keyword in your python version. We can also check specific word is keyword or not using of iskeyword() function. let take one example.
#check given word is keyword or not import keyword #checking given keyword is valid or not print("for :",keyword.iskeyword("for")) #True print("in :",keyword.iskeyword("in")) #True print("switch :",keyword.iskeyword("switch")) #False print("this :",keyword.iskeyword("this"))#False
for : True in : True switch : False this : False
Dynamic Data Type :This is most smart features of python programming. in other programming language like c,c++, java are need to define initial data type of every variable. but this language are cannot need to defined any data type of variable. for example.
#Define a variable #Provide initial string value info="Python Programming" #Display type of variable print(type(info)) #Modified variable value info=7 print(type(info)) #Modified variable value info=9.23 print(type(info))
<class 'str'> <class 'int'> <class 'float'>
Note that single variable are work different different data type. and there are no need to define its proper data type.
Python Debugger: Debugging is a way to trace the execution flow of program and they are capable to change the execution flow. That is very useful technique to find logical error and mistake. let take one example.
#Trace execution of this program result=1 #"for loop" to display of table of number 2 for i in range(1,11): result=i*2 print(result) #display result
This is an python code we can try to trace execution of this program. first need to save this file. save this file using any name like test.py. And open a terminal on this file location. if your are use windows OS then open cmd. note that cmd directive path are located to your file location (test.py).
After that run this program using this command "python test.py". output of this program is this.
#command: python test.py 2 4 6 8 10 12 14 16 18 20
after that try to run this program using debugger mode. syntax of debugging mode is like this.
python -m pdb source_file.py #-m is mode # pdb python debugger module # source_file is file name
so on run this program using debugger mode using "python -m pdb test.py".
python -m pdb test.py > /location/test.py(2)
() -> result=1 (Pdb)
After that we are ready to trace out our program. there are various option are in debugging mode. so we will first view all of possible command. simply type ? (question mark) after the (Pdb). then see following options.
(Pdb) ? Documented commands (type help <topic>): ======================================== EOF bt cont enable jump pp run unt a c continue exit l q s until alias cl d h list quit step up args clear debug help n r tbreak w b commands disable ignore next restart u whatis break condition down j p return unalias where Miscellaneous help topics: ========================== exec pdb Undocumented commands: ====================== retval rv (Pdb)
There is following option are available to use in debugging mode. first use to check list option. this are display our code. use (Pdb) list
(Pdb) list 1 #Trace execution of this program 2 -> result=1 3 4 #"for loop" to display of table of number 2 5 for i in range(1,11): 6 result=i*2 7 print(result) #display result [EOF] (Pdb)
(Pdb) list are display above result. now if your are not get this result then using a ((Pdb) restart ) command.
(Pdb) restart Restarting test.py with arguments: > /location/test.py(2)<module>() -> result=1 (Pdb)
after that use ("n") command that are execute next instruction
(Pdb) n > /location/test.py(5)<module>() -> for i in range(1,11): (Pdb) n > /location/test.py(6)<module>() -> result=i*2 (Pdb) n > /location/test.py(7)<module>() -> print(result) #display result (Pdb) n 2 > /location/test.py(5)<module>() -> for i in range(1,11): (Pdb)
In this example uses 4 time 'n' (next) option. similarly we can also print variable value also. see example.
(Pdb) print(result) 4
This was an simple example most of case problem is complex so similar way we can find out logical error and trace execution flow of any code.