یکی از فانکشن ها که میتونه در خیلی جاها کمکتون کنه فانکشن dir هستش
این فانکش میتونه یک آرگومان بگیره و یا نگیره
اگر بهش آرگومانی پاس ندید اسم متغییر ها و آبجکت ها در محیط فعلی رو برمیگردونه
و اگر بهش آرگومانی پاس بدیم دوتا حالت پیش میاد اگر اون آبجکت ما مجیک متد dir رو داشته باشه اون رو خروجی میده و اگر نداشته باشه :
برای ماژول ها: ویژگی های ماژول رو برمیگردونه
برای کلاس ها:ویژگی های خود کلاس و ویژگی های وراثتی از کلاس های پایه اش
برای باقی آبجکت ها : ویژگی های خودش ، ویژگی های کلاسش به همراه ویژگی های کلاس های پایه اش
چنتا مثال:
1
a,b,c,d=10,20,"ccc","dddd"
print(dir())
'''Out
['__builtins__', '__file__', '__name__', '__warningregistry__', 'a', 'b', 'c', 'd']
'''
2
def one():
return dir()
def two():
a,b=5,10
return dir()
print(one());print(two())
'''Out
[]
['a', 'b']
'''
3
print(dir(str))
'''Out
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
'''
📱
@comma_code_python1
📱comma.code
📱COMMA_CODE_YOUTUBE