Python is a object oriented programing language in which the underlying codes are in C. It also supports functional programming. It is dynamic typed language, i.e., it doesn't require any type declarations. It is considerably slow compared to C.
When programming using python don't compare it with C or CPP. here any thing can be assigned to a variable.
Eg:
a=1 then a integer value 1 is assigned to a.
a=1, then a tuple (1,) is assigned to a.
a=[1,2] then a list [1,2] is assigned to a.
a='hello' then a string 'hello' is assigned to a.
List in python
A list is a collecton of any type. There is a function called range(), which have three parameters- start, stop and step.It will give a list according to these parameters. for eg:
>>>range(10)
[0,1,2,3,4,5,6,7,8,9]
Here it take the value start=0, stop=10 and step=1
>>>range(4,10,2)
[4,6,8]
Here start=4, stop=10, step=2
Hash or associative array/directory
It will have keys and a value corresponding to each key. eg:
>>>a={'key1':2,'key2':3,'key3',5}
by calling a.keys() will provide a list of keys and a.values() will provide a list of values
>>>a.keys()
['key1','key2','key3']
>>>a.values()
[2,3,5]
>>> a.items()
[('key1',2),('key2',3),('key3',5)]
Functions in python
No comments:
Post a Comment