डेवलपर्स के लिए Python परिचय
Jasmin Ludolf
Senior Data Science Content Developer
# सामग्री के नामों के वैरिएबल्स
ingredient_one = "pasta"
ingredient_two = "tomatoes"
ingredient_three = "garlic"
ingredient_four = "basil"
ingredient_five = "olive oil"
ingredient_six = "salt"
# सामग्री की सूची
ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]
# वैरिएबल्स को मानों की तरह उपयोग कर सूची बनाना
ingredients = [ingredient_one, ingredient_two, ingredient_three,
ingredient_four, ingredient_five, ingredient_six]
# सूची के डेटा टाइप की जाँच करें
print(type(ingredients))
<class 'list'>
# सूची वैरिएबल के सभी मान प्रिंट करें
print(ingredients)
['pasta', 'tomatoes', 'garlic', 'basil', 'olive oil', 'salt']
[]a_list[index]ingredients = ["pasta", "tomatoes",
"garlic", "basil", "olive oil", "salt"]
# पहले इंडेक्स का मान लें
print(ingredients[0])
pasta
# चौथा तत्व लें
print(ingredients[3])
basil
ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]
# सूची का आखिरी तत्व लें
print(ingredients[5])
salt
# सूची का आखिरी तत्व लें
print(ingredients[-1])
salt
ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]
# दूसरा और तीसरा तत्व एक्सेस करें
print(ingredients[1:3])
["tomatoes", "garlic"]
[first_element:last_element + 1]ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]
# तीसरे इंडेक्स से आगे के सभी तत्व एक्सेस करें
print(ingredients[3:])
['basil', 'olive oil', 'salt']
# पहले तीन तत्व लें
print(ingredients[:3])
['pasta', 'tomatoes', 'garlic']
ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]# हर दूसरे तत्व तक पहुँचें print(ingredients[::2])
['pasta', 'garlic', 'olive oil']]
# दूसरे से शुरू करते हुए हर तीसरे तत्व तक पहुँचें
print(ingredients[1::3])
['tomatoes', 'olive oil']
डेवलपर्स के लिए Python परिचय