কম্পিউটার টিউটোরিয়াল

পাইথন ভেরিয়েবল অস্তিত্ব আছে কিনা যাচাই করার পদ্ধতি

পাইথনে ভেরিয়েবল অস্তিত্ব আছে কিনা যাচাই করার জন্য নিচের কোডটি ব্যবহার করা হয়।

উদাহরণ

x = 10
class foo:
    g = 'rt'
    def bar(self):
        m = 6
        print(locals())
        if 'm' in locals():
            print('m is local variable')
        else:
            print('m is not a local variable')

f = foo()
f.bar()
print(globals())
if hasattr(f, 'g'):
    print('g is an attribute')
else:
    print("g is not an attribute")
if 'x' in globals():
    print('x is a global variable')

আউটপুট

{'self': <__main__.foo instance at 0x0000000002E24EC8>, 'm': 6}
m is local variable
{'f': <__main__.foo instance at 0x0000000002E24EC8>, '__builtins__': , '__file__': 'C:/Users/TutorialsPoint1/~.py', '__package__': None, 'x': 10, '__name__': '__main__', 'foo': , '__doc__': None}
g is an attribute
x is a global variable
Process finished with exit code 0
  1. জাভাস্ক্রিপ্টে ভেরিয়েবল অস্তিত্ব আছে কিনা কীভাবে চেক করবেন?

  2. সি-এ ভেরিয়েবল নাম প্রিন্ট করা

  3. পাইথনে ভেরিয়েবলটি টাপল কিনা চেক করা

  4. পাইথনে প্যাটার্ন প্রিন্ট করার পদ্ধতি