Posts

Dictionary in python

*Dictionary in python* Dictionary A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values. Example Create and print a dictionary: thisdict = {    "brand" : "Ford" ,    "model" : "Mustang" ,    "year" : 1964 } print (thisdic) OUTPUT:- { "brand" : "Ford" , "model" : "Mustang" , "year" : 1964 }   Accessing Items You can access the items of a dictionary by referring to its key name, inside square brackets: Example Get the value of the "model" key: x = thisdict[ "model" ] print(x) OUTPUT:- "Mustang" OR There is also a method called get() that will give you the same result: Example Get the value of the "model" key: x = thisdict.get( "model" ) print(x)  OUTPUT:- "Mustang" Ch...

List in python

* LIST IN PYTHON * List is a collection which is ordered and changeable. Allows duplicate members. means you can add same data  in list as well as change the list data ,size(length), etc.. A list is a collection which is ordered and changeable. In Python lists are written with square brackets. Example Create a List: thislist = [ "apple" , "banana" , "cherry" ] print (thislist) OUTPUT   :-  [ "apple" , "banana" , "cherry" ] Access Items You access the list items by referring to the index number: Example Print the second item of the list: thislist = [ "apple" , "banana" , "cherry" ] print (thislist[ 1 ]) OUITPUT:-   "apple" Change Item Value To change the value of a specific item, refer to the index number: Example Change the second item: thislist = [ "apple" , "banana" , "cherry" ] thislist[ 1 ] = "blackcur...

tuples in python

Sorry guys i am let because my External exam are currently runing but i will provide lesson every day to you from now        * Tuples *   Tuples:- A tuple is a sequence of immutable (unchange able) Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. Creating a tuple is as simple as putting different comma-separated values. Optionally you can put these comma-separated values between parentheses also. Example:- tup1 = ('physics', 'chemistry', 1997, 2000); tup2 = (1, 2, 3, 4, 5 ); tup3 = "a", "b", "c", "d";   Accessing Values in Tuples To access values in tuple, use the square brackets for slicing along with the index or indices to obtain value available at that index. For example − tup1 = ( 'physics' , 'chemistry' , 1997 , 2...