Python Variable and Data types:
In python variable and data types are very interesting, how variable and objects work.In this chapter we will discuss how variable and object are work together in comparison to other languages.In python variable or name is not have a type associated with them.Basically types are only associated with objects and variable are basically just have references these objects.
1
Let us see what’s the meaning of above para:
2
In other language you have to ideally defined string and other types ,In python you don’t need to do this at all. Variable name is just a reference to the objects now this object which is the string “Buffercode” which has a type string associated with it.If you can see the another example. If you are interested to finding out the exact memory location in which the object is stored you can do it in two ways by either using id function or going header using “repr” an attribute inside in a object ,see this example. In using id function it can give the value and you can change into hexadecimal value because in case O.S computer every address is represent in hex value .In use of repr it can automatically represent the current address of an object and type of object. In Python basically many types of data types are there but some mostly Data types are 1. String 2. Number 3. Lists 4. Dictionaries 5. Tuples 6. Boolean …
3
String:
First is the “string ” most familiar among all of the above data types because in every language String is use widely.Multiple method to define a string are: triple quotes are used as the commenting feature
Unicode String:
Unicode is basically use for standardization because uni-code is referred to wide character allows to encode all of these different letter or languages in an a easy way. in above example the “u ” tells us this is unicode String are immutable objects in Python String Operation In String Operation we can use many types of operation like Concatenating , Repetition , Slicing, Conversion to another and other. 1. Concatenating String (addition to two String) >>> firstname = “vipin” >>> lastname = “kumar” >>>firstname+lastname >>> ‘vipinkumar’ Repeated Sequence in String >>buffer= “B”*20 Slicing (breaking up the String) string[start:end:steps] like >>>name = “vipin kumar” >>>name [5:10] >>>’kumar’ Conversion >>>str(42) In string number of different method ,techniques and operation are there Like in String method we can use: string.find(…) string.replace(…) string.split(…) these methods are common and important in python.
Numbers:
Integer,Float,Double and etc. operators 1. Arithmetic ( +,-*,/ ) 2. x**y (x to the power y) 3. Comparison (>,=,<,<=,>=,==) 4. Bit wise (X|Y ,X&Y,..) 5 .Logical (and, or, not)
Lists:
Lists a collection of objects which can be heterogeneous list can be nested In list many types of operation can be performed some of these are there Append — list.append() Extend — list.extend([]) Reverse –list.reverse() Pop — list.pop() Insert — list.insert(index,item) Delete –del list[index]
4
//