Lastest update done on August 1, 2019 at 02:57 pm

This post understands that you now have very basic understanding on what a list is. If not, I would recommend reading basics of python lists.

The most common data operations that we do on any data structure is, CRUD

Create – Read – Update – Delete

Let’s see how we do this using python lists,

Create

You can add data to list using append method.

As you can see in #9 & #11 adds a int & string type data respectively to the list, which outputs as in #14.

If we want to add a list of items to existing list then we should use extend instead of append method. As given in #18.

Suppose we want to add a list to the existing list instead of list of items, then we can use append method. As given in #23

Take away

  1. append -> adds data to the list, irrespective of its type
  2. extend -> adds each element in the iterable data

Read

We can read the element of a list using its index / position of the element in the list.

Lastest update done on May 11, 2019 at 09:56 pm

Statically typed, will need to always declare of what type of data will be used for the declared variable, say either int, float or string upfront before using it.

Dynamically typed, will internally declare its type based on the type of the data it is holding or assigned to.

Dynamically TypedStatically Typed
PythonC
JavascriptC++
RubyJava

For example, let’s consider python for dynamically typed

The above snippet a first shows that it is a string and in the second assignment we try to assign int value, as it is dynamically typed it switches its data type from string to int, without any errors.

Now for statically typed, lets consider C language

Here first we try to assign a str to a, this prints out successfully. Now if we try to assign int value to a, the compiler itself will throw an error as below.

static_typed.c: In function ‘main’:
static_typed.c:7:3: error: assignment to expression with array type
 a = 10;
   ^

Lastest update done on October 25, 2019 at 05:52 pm

Data is very important in all aspects, the way data is stored and organized, so that we can use it in a meaningful way is known as data structures.

In that note python also has very interesting data structures in it, here is the primary summary list,

  1. List
  2. Dict
  3. Set
  4. Tuple

List

List is more likely an array or a sequence of logical elements grouped together.

Elements enclosed with [ ] brackets are known as lists in python.

l = [1, 2, 3, 4, 5]
print(l)

type will return the type of the variable. Now the variable l denotes that its a list of numbers from 1 to 5.

Each element in the list can be acceseed by its index. The index starts from 0 and not from 1

This is a very basic implementation of list, we can do much more.

Dict

Dict is basically a key, value pair. We can assume, key as the variable name holding its value.

Its values are enclosed with { } brackets.


Each value in the dict can be acceseed by its key.

This is a very basic implementation of dict, we can do much more.

Set

It is as same as list, logically grouping of elements. But the prime difference is that unlike list

  1. It doesn’t allow duplicates (Line #6 & #9)
  2. It will be ordered list of elements (Line #9)
  3. It doesn’t support indexing (Line #11)

Its values are enclosed with { } brackets.

The only way of accessing elements is through iteration. Hold on does the iteration give exact order of result expected? (Line #18)

Tuple

Tuple is same as list, logical group of elements. The only difference is that tuples are immutable where a list is mutable.

Its values are enclosed with ( ) brackets

These are base data structures used in python. With these we will be able to implement much more complex data structures like linked list, Queue.

Lastest update done on May 11, 2019 at 09:59 pm

python installation in windows

In Contrast to Linux, python doesn’t come out of the box with windows. We need to manually install it.
Very minimal steps are required to make you up and running with it.

The environment in which this post deals about is with,
Windows 10
Python 3.7.3

If you are very curious about how to install a version which is < 3.7, well this procedure itself will work well. Here we go,

1. Download Python here
2. Make sure you get the Windows x86-64 executable installer
3. While running the EXE file, make sure you select “Add Python 3.7.3 to PATH”.
4. The above step will ensure that you can access python console right from your windows command prompt by commanding python.

Voila!! Now you have the latest python installed in your machine.

And finally to make sure everything went good,  

  1. Open windows command prompt and command python
  2. You will get a python shell right away
  3. Add the below snippet
    >>> print('Hello World!!! Welcome!')