Once Again we are here with some python - Lists .
Commonly List is expressed as it contains some similar materials like groceries bought from the market . Here is my question do you really bring only the groceries item when you come from market ?
Ans : No, You will be packing up some other materials like news paper and something kinda Stuff .
Then what is List in Python - Similar to the example explained, List is a container where holds the data (int, String, Char, Double, Float and etc..)
Syntax :
a = ['', '']
Example :
>>> a = [1, 2, 3, 4]
>>> a
[1, 2, 3, 4]
>>> b = a
>>> b[2] = 5
>>> b
[1, 2, 5, 4]
>>> a
[1, 2, 5, 4]
# Above Example 1 shows you value a address to value b
# if you try to change in b it adversely effect with a too :)
# So, we have some functions in here
>>> c = list(a)
>>> c
[1, 2, 5, 4]
>>> c[3] = 12
>>> c
[1, 2, 5, 12]
>>> a
[1, 2, 5, 4]
# Now this Example shows that a != c , even with address .
# if you attempt to change c, it does not affect a .
# Now we append some values inside the list
>>> c.append('Prasanna')
>>> c
[1, 2, 5, 12, 'Prasanna']
# As i already said , you can insert any data type values inside the List .
# Some Common Function and usage
Function - Explaination
c.pop(params) - params is the Position of the value, if params == " " then it
pops out the last value
No comments:
Post a Comment