Starting up with Python – Part4

I should admit it was pretty fast and very interesting to hack in Python. Looks like everything is just pretty easy for the time being. The Python articles published for your references are as follows:

8.More List Functions

We can also extract the minimum and maximum length within a list using the function max and min

>> number = [8,4,50,23,4,0,43]
>>> len(number)
7
>>> max(number)
50
>>> min(number)
0
>>> number
[8, 4, 50, 23, 4, 0, 43]
>> list('hackers')
['h', 'a', 'c', 'k', 'e', 'r', 's']

Changing and deleting an element within a list can also be done pretty fast.

>> number = [8,4,50,23,4,0,43]
>>> number[3] = 10
>>> number
[8, 4, 50, 10, 4, 0, 43]
>> del number[0]
>>> number
[4, 50, 10, 4, 0, 43]

9. Slicing lists

A list can also be replaced by counting as from 0 up to the letter we want to replace

>> name = list ('HackersMauritius')
>>> name
['H', 'a', 'c', 'k', 'e', 'r', 's', 'M', 'a', 'u', 'r', 'i', 't', 'i', 'u', 's']
>>> name[7:]=list('worldwide')
>>> name
['H', 'a', 'c', 'k', 'e', 'r', 's', 'w', 'o', 'r', 'l', 'd', 'w', 'i', 'd', 'e']

Elements can be deleted in a list using slicing

>> numbers=[0,1,2,3,4,5]
>>> numbers[1:3]=[]
>>> numbers
[0, 3, 4, 5
Nitin J Mutkawoa https://tunnelix.com

Blogger at tunnelix.com | Founding member of cyberstorm.mu | An Aficionado Journey in Opensource & Linux – And now It's a NASDAQ touch!

You May Also Like

More From Author