Dictionary in Python like list is a collection of objects.Unlike lists ,items in dictionary are accessed by key.Similar to lists ,items can be added or removed from dictionary.While the items in a list are sorted in a specific order ,the items in a dictionary are not sorted.The size of dictionary is not fixed ,items can […]
Declaring a class We define a class in Python using the class keyword.To define a class called Main we use the following:
There are few important points to be noted in the above code: 1.Class is defined using the class keyword.Here the name of the class is Main. 2.Class initialization happens in a method […]
list is a data type in Python which consists of a group of elements.The elements are declared in a pair of square brackets.For example to declare a simple list you can use the following:
you can even mix elements of different types in a list as:
The items in the list can be […]
with statement was introduced in Python 2.5 and is quite useful when you want to work with a resource and then want to dispose/close it when you are done. The with statement is used for writing blocks of code when we want to call methods as defined by context.It allows to write block of code […]
Determine variable type in Python To get the type of a variable in python you can use the built in type() method.
output: <class ‘int’> In the following code we are printing the value the data type of variable x.
print("variable is integer")
print("variable is string")
print("variable is float")
If you execute the code above then the following will be printed: variable […]