Posts

Python Arrays

Image
Arrays are fundamental part of most programming languages. It is the collection of elements of a single data type, eg. array of  int , array of  string . However, in Python, there is no native array data structure. So, we use Python lists instead of an array. Note:  If you want to create real arrays in Python, you need to use NumPy's array data structure. For mathematical problems, NumPy Array is more efficient. Unlike arrays, a single list can store elements of any data type and does everything an array does. We can store an integer, a float and a string inside the same list. So, it is more flexible to work with. [10, 20, 30, 40, 50 ]  is an example of what an array would look like in Python, but it is actually a list. Create an Array We can create a Python array with comma separated elements between  square brackets[] . Example 1: How to create an array in Python? We can make an integer array and store it to ...

Python Data Types

Image
Although we don’t have to declare type for python variables, a value does have a type. This information is vital to the interpreter. Python supports the following Python data types. a. Numbers There are four numeric Python data types. 1. int – int stands for integer. This Python Data Type holds signed integers. We can use the type() function to find which class it belongs to. > > > a = - 7 > > > type ( a ) <class ‘int’> An integer can be of any length, with the only limitation being the available memory. > > > a = 9999999999999999999999999999999 > > > type ( a ) <class ‘int’> 2. float – This Python Data Type holds floating point real values. An int can only store the number 3, but float can store 3.25 if you want. > > > a = 3. 0 > > > type ( a ) < class 'float' > 3. long  – This Python Data Types holds a long integer of unlimited length. But this c...