Home > Pemprograman > The Differences between Tupple, List dan Dictionary

The Differences between Tupple, List dan Dictionary

sometimes, we got wrong perception about the using of tupple, list and dictionary, when we use all of them? what is the function?

ok, after i read an article and reference about python fundamental.. i get  this point. let’s check

  • List.. is the type of variable that we can use to accept many of data and bundle or accomodate it into one variable. we usually use array in java and C programming languange, but in python, we can use List. here the pattern :
    name_of_list = [data1,data2,data N]
    For instance : list = [‘octav’,123,True]

    Here is the examples of using list (i ran it in python 2.7.2 with ubuntu 11)

    in feature above, we can call list per element. for instance list[0] .. it means, we just call list which element is 0, so the result is ‘intan’ or we can call of that element, just type ‘list’

  • Tupple..
    what is tupple? what is the differences between tupple and list? as i know, list declare and using [] but, in tupple, we use ()

    Pattern :
    name_tupple = (data1,data2)
    for instance :
    tupple = (‘octav’,123)

    here is example:
    looking at first sentences, it means, we put data in variable ‘tupple’ and we can call it again later using ‘tupple’, but if you want to change your data later, it can’t.. so The differences of tupple and list is tupplue can’t permit changing of data, but, in list, you can change your data later for instance tupple[0] =’asd’ the result is error

  • Dictionary..
    Dictionary is the type that produce random data.. looking at this print screen below:
    dict = {} #to declare your dictionary which name is ‘dict’
    dict[0] = ‘octav’ #give a value to index 0 which value is ‘octav’
    dict[‘satu’] = 123 #give a value to index ‘satu’ which value is 123
    dict[‘satu’] #print your dictionary which name is dict

    another format is, declare your dictionary with all of your list.for instance :
    opendict = {12:’octav’,’octav’:12}


Categories: Pemprograman
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s