Learn Python in Marathi - Part 4 - Lists

आज आपण पायथॉन मध्ये लिस्टचा वापर करण्याच्या काही पद्धती शिकू

Finding numbers of items in a list

लिस्ट मध्ये किती गोष्टी/ वस्तू  आहेत हे  लिस्ट न पाहता जाणण्यासाठी आपण लेन (len) या फंक्शन चा वापर / प्रयोग करू शकतो.
mylist = ['Dehli', 'Washington', 'Tokyo']
len(mylist)
 3


mylistpair = [('India','Dehli'),('USA','Washington'),('Japan','Tokyo')]
len(mylistpair)
 3



Traversing through the items in a list

पायथॉनच्या लिस्ट मधील सर्व नावांना  कशा रीतीने प्रिंट करता येते/ लिहून काढता येते ते आपण पाहू.

names = ["Sanjay", "Abhay", "Shailaja", "Vinay", "Ishaan"]
for name in mynames:
    print("Hello",name)

Hello Sanjay
Hello Abhay
Hello Shailaja
Hello Vinay
Hello Ishaan

mynumbers = [11, 22, 33, 44, 55, 66]
for num in mynumbers:
    print("Square of number", num, "is",num*num)

Square of number 11 is 121
Square of number 22 is 484
Square of number 33 is 1089
Square of number 44 is 1936
Square of number 55 is 3025
Square of number 66 is 4356


Using enumerate

लिस्ट मधील सर्व नावांना आणि त्यांच्या क्रमांकाला कसे लिहिता येते ते आपण पाहू

mylist = ['Dehli', 'Washington', 'Tokyo', 'Mosco', 'London']
for index, name in enumerate(mylist):
    print("The city" , name , "is ", str(index) , " position in  the list")


The city Dehli is  0  position in  the list
The city Washington is  1  position in  the list
The city Tokyo is  2  position in  the list
The city Mosco is  3  position in  the list
The city London is  4  position in  the list

यापुढील लेख


टिप्पण्या