Monday, 27 January 2020

pass keyword

"pass" is a keyword which is used to execute nothing; means, when we don't want to execute code, the pass can be used to execute empty.
If we want to bypass any code pass statement can be used.


Difference between continue and pass
 

Continue

Pass

s = "python"

# Continue statement

for i in s:

        if i == 'h':

                print('Continue executed')

                continue

        print(i)

s = "python"

# Pass statement

for i in s:

        if i == 'h':

                print('Pass executed')

                pass

        print(i)

print()

P

y

t

Continue executed

o

n

P

y

t

Pass executed

h

o

n

 

 

 

Difference b/w pass and break and continue

Pass

Break

Continue

s = "python"

# Pass statement

print("example on pass")

for i in s:

        if i == 'h':

                print('Pass executed')

                pass

        print(i)

print()

# break statement

s = "python"

print("break example")

for i in s:

        if i == 'h':

                print('break executed')

                break

        print(i)

s = "python"

# Continue statement

print("example on continue")

for i in s:

        if i == 'h':

                print('Continue executed')

                continue

        print(i)

example on pass

p

y

t

Pass executed

h

o

n

break example

p

y

t

break executed

example on continue

p

y

t

Continue executed

o

n

 

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(...