Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Python loops ( python part 12 ) in Hindi


 Python loops

loop का उपयोग program में statements को दिए हुए condition के आधार पर repeat करने के लिए किये जाते है। python में loops के प्रकार निम्न है।

  1. for
  2. while
  3. nested loops

1) for loop

days = ["sunday", "monday", "tuesday", "thursday", "friday", "saturday"]
for x in days:
  print(x)

2) while loop

no = 1
while no < 10:
  print(no)
  no += 1

3) Nested loops

दूसरी programming languages की तरह python में ही loop को दूसरे loop के अंदर लिखा जा सकता है इसे ही nested loop कहते है।

Example

no = [1, 2, 3, 4, 5, 6, 7]
days = ["sunday", "monday", "tuesday", "thursday", "friday", "saturday"]

for x in no:
  for y in days:
  print(y, x)

Comments are closed.


एक टिप्पणी भेजें

0 टिप्पणियाँ