Posts

Showing posts with the label datatypes

What are the different data types in Python?

Python Datatypes : Boolean Numbers Strings Lists Tuples Sets Dictionaries Boolean : Booleans are either true or false. Python has 2 constants named True and False which can be used to assign a boolean value directly. In certain places ( like if statements ), Python expects an expression to a boolean value, these places are called boolean contexts. Numbers : Python supports both int and floating point numbers. Tuples : A tuple is an immutable list, it means a tuple can't be changed in a way once it's created. A tuple is defined in the same way as a list, except that the whole set of an element is enclosed in the parenthesis instead of square brackets. Similarities with the list  : Tuples have a defined order i.e. Indices are 0 based, so the first element of a non-empty tuple is always a_tuple[ 0 ]. Negative indices count from the end of the tuple. Slicing works too, when we slice a list we get a new list. When we slice a tuple, we get a new t