Posts

Showing posts with the label Python

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.