for और while लूप

इंटरमीडिएट Python फॉर फाइनेंस

Kennedy Behrman

Data Engineer, Author, Founder

कोड ब्लॉक दोहराना

CUSIP

037833100

17275R102

68389X105

SYMBOL

AAPL

CSCO

ORCL

इंटरमीडिएट Python फॉर फाइनेंस

लूप्स.

For loop

While loop

इंटरमीडिएट Python फॉर फाइनेंस

स्टेटमेंट के घटक

<Control Statement>
    <Code Block>
execution 1
execution 2
execution 3
इंटरमीडिएट Python फॉर फाइनेंस

For लूप्स

for <variable> in <sequence>:
for x in [0, 1, 2]:
d = {'key': 'value1'}
for x in d:
for x in "ORACLE":
इंटरमीडिएट Python फॉर फाइनेंस

लिस्ट उदाहरण

for x in [0, 1, 2]:
    print(x)
0
1
2
इंटरमीडिएट Python फॉर फाइनेंस

डिक्शनरी उदाहरण

symbols = {'037833100': 'AAPL',
           '17275R102': 'CSCO'
           '68389X105': 'ORCL'}
for k in symbols:
    print(symbols[k])
AAPL
CSCO
ORCL
इंटरमीडिएट Python फॉर फाइनेंस

स्ट्रिंग उदाहरण

for x in "ORACLE":
    print(x)
O
R
A
C
L
E
इंटरमीडिएट Python फॉर फाइनेंस

While कंट्रोल स्टेटमेंट्स

while <expression>:
इंटरमीडिएट Python फॉर फाइनेंस

While उदाहरण

x = 0

while x < 5:
    print(x)
    x = (x + 1)
0
1
2
3
4
इंटरमीडिएट Python फॉर फाइनेंस

अनंत लूप्स

x = 0

while x <= 5:
     print(x)
इंटरमीडिएट Python फॉर फाइनेंस

continue से स्किप करना

for x in [0, 1, 2, 3]:
   if x == 2:
       continue
   print(x)
0
1
3
इंटरमीडिएट Python फॉर फाइनेंस

break से रोकना.

while True:
    transaction = get_transaction()
    if transaction['symbol'] == 'ORCL':
        print('The current symbol is ORCL, break now')
        break
    print('Not ORCL')
Not ORCL
Not ORCL
Not ORCL
The current symbol is ORCL, break now
इंटरमीडिएट Python फॉर फाइनेंस

आइए 'for' और 'while' लूप्स का अभ्यास करें!

इंटरमीडिएट Python फॉर फाइनेंस

Preparing Video For Download...