Posts

Exception in handling in python.

Image
1) These are key methods to handle the error in python. Try catch is useful for when error occurs then program stop their and after this execution is not work. 2) So by using try except your program easily handle that error and ran further for completion. 3) If you don’t handle these error then python throws an error message which cryptic or not easily understandable by the nonprogramming person so that’s why is a good practice a write a code in a try except block which handles a error and message which provide an easy way to understand end user. 4) When you got error message and stack trace on console these are uncaught exceptions

All about function and arbitrary number of argument and named parameter in Python.

Image
1) The function is a code of block which you call again and again and there is no need to write the same code again and again. There are 2 types of function inbuilt and custom made. len() ,sys.exit(). 2) Also when you write a function you need to write code inside this and if you do not want to write a code then simply put pass as word inside this. 3) There are several types of functions parametrize an optional argument in python.Also, you have to remember that id optional argument is last in series or place before default parameter you not able to write this. 4) Also for the optional parameter, you are able to assign none value. Which is a special value. 5) Also sometimes you need an arbitrary number of argument to functions by * before the variable name. It is tuple type and before that you able to write optional and default parameter also. 6) There is also another type where you can pass variable data by using named parameter and in that function, you need to use ** two aster...

Basic of If else,loops in python

Image
1) If else is used to write a conditional statement in python. 2) Loops are used to iterate some statement until condition false or elements on which it iterates are completed. 3) 2 types one For loop second is While loop

Explain string type In python

Image
1) Internally string is an array and treat as array of char.  2) Is immutable object and created with single quotes or double quotes.  3) You can use escape char in between string. If you use r letter before string then its meaning is raw string.  4) Formatting also applied on string in python 3.6. Curly braces are replaced by format method value in python 3 version.  >>> n=42  >>>  s=this is my string. No is {}.format(n) >>> print(s) this is my string. No is 42 5) We can not change the or assign value in between string be coz string is immutable.  Ex. s[1]=j -- is impossible. 

Sequential types in python

Image
A) Tuple – If I use () this kind of braces then it makes a tuple. Is immutable and when u going to change that element a specific position it gives an error. x=(1,2,3,) >>> x (1, 2, 3) >>> type(x) b) List When we use [ ] this kind of braces then it makes a list and it is mutable. So you can modify by appending a value. Also, list can contain list inside this also. a=[[10,20],[10,20,30]] ——list inside list >>> y=[1,2,3] >>> y [1, 2, 3] >>> y[1]=sagar >>> y [1, Sagar, 3] >>> type(y) Index – is used to find out index of element in list c.index(2) append- it append or insert an element at last position of the list >>> c.append(5) Insert – it is used to insert an element at a specific position in the list and you have to give 2 parameters to insert method one is a position where to insert and other is a specific element. c.insert(4,5) c) Dictionary  Use curly brace notation f...

Mutable And Immutable types in python?

Image
1) Everything in python 3 objects. So Every object has Id, type and value and id uniquely identifies an object and it can not change throughout life of object 2) Also, type identifies a class of an object and also it cannot change throughout the life of an object. 3) Values are the content of the object. 4) Most Fundamental types in python are immutable -number, string, tuples 5) Mutable object change value but immutable may not you can verify this by using id method so if it is changed then it is immutable or if not then it’s mutable.

Basic about python Language.

Image
1) It doesn't need a semicolon to recognize the line end. 2) In python everything in an object so when print (“Hello world”) call this method then word inside print are represent string. 3) If you want to find syntax of any command then use help command and whose syntax is help(“print”) 4) Rules of creating variables aaBB09_ mean you can use small letter, capital letter and numeric 0-9 and underscore. Variable cannot start with the numeric value. 5) Everything in python 3 objects.