परिचय और लिस्ट्स

Python में डेटा टाइप्स

Jason Myers

Instructor

डेटा टाइप्स

  • डेटा टाइप सिस्टम भाषा की क्षमताएँ तय करता है
  • डेटा टाइप समझने से आप एक डेटा साइंटिस्ट के तौर पर सक्षम बनते हैं
Python में डेटा टाइप्स

कंटेनर सीक्वेंस

  • अन्य टाइप का डेटा रख सकते हैं
  • एग्रीगेशन, सॉर्टिंग आदि में काम आते हैं
  • म्यूटेबल (list, set) या इम्यूटेबल (tuple) हो सकते हैं
  • Iterable
Python में डेटा टाइप्स

लिस्ट्स

  • डेटा उसी क्रम में रखते हैं जिस क्रम में जोड़ा गया
  • म्यूटेबल
  • इंडेक्स
Python में डेटा टाइप्स

लिस्ट में एक आइटम तक पहुँचना

cookies = ['chocolate chip', 'peanut butter', 'sugar']
cookies.append('Tirggel')
print(cookies)
['chocolate chip', 'peanut butter', 'sugar', 'Tirggel']
print(cookies[2])
sugar
Python में डेटा टाइप्स

लिस्ट्स को जोड़ना

  • ऑपरेटर्स से, आप दो लिस्ट्स को जोड़कर नई लिस्ट बना सकते हैं
cakes = ['strawberry', 'vanilla']

desserts = cookies + cakes

print(desserts)
['chocolate chip', 'peanut butter', 'sugar', 'Tirggel', 'strawberry', 'vanilla']
  • .extend() मेथड एक लिस्ट को दूसरी लिस्ट के अंत में मर्ज करता है
cookies.extend(cakes)
Python में डेटा टाइप्स

लिस्ट में एलिमेंट ढूँढना

  • .index() मेथड लिस्ट में किसी एलिमेंट की पोज़िशन बताता है
position = cookies.index('sugar')

print(position)
2
Python में डेटा टाइप्स

लिस्ट से एलिमेंट हटाना

  • .pop() मेथड लिस्ट से एक आइटम हटाता है और उसे सेव करने देता है
name = cookies.pop(position)

print(name)
sugar
print(cookies)
['chocolate chip', 'peanut butter', 'Tirggel']
Python में डेटा टाइप्स

लिस्ट्स पर इटरेट करना

  • List comprehensions लिस्ट पर इटरेट कर कोई क्रिया करने का सामान्य तरीका है
titlecase_cookies = [cookie.title() for cookie in cookies]
print(titlecase_cookies)
Chocolate Chip
Peanut Butter
Tirggel
Python में डेटा टाइप्स

लिस्ट्स को सॉर्ट करना

  • sorted() फंक्शन डेटा को न्यूमेरिकल या अल्फाबेटिकल क्रम में सॉर्ट कर नई लिस्ट देता है
print(cookies)
['chocolate chip', 'peanut butter', 'Tirggel']
sorted_cookies = sorted(cookies)

print(sorted_cookies)
['Tirggel', 'chocolate chip', 'peanut butter']
Python में डेटा टाइप्स

अभ्यास करते हैं!

Python में डेटा टाइप्स

Preparing Video For Download...