About 137,000 results
Open links in new tab
  1. Is it a good practice to declare instance variables as None in a …

    By the way: using a proper python IDE (e.g. PyCharm), setting the attributes in the __init__ already provides autocompletion etc. Also, using None prevents the IDE to infer a better type …

  2. python - Is it better practice to set default values for optional ...

    Sep 13, 2024 · The default ensures that the target (args.a) exists with or without a command-line argument -a to create it. You can define p.add_argument('-a'), and it is by default optional and …

  3. Best practice for Python main function definition and program …

    Nov 2, 2020 · The default value for the main is a parse_args('') call with an empty string, which initializes the namespace with all values as None instead of getting sys.argv by itself. To make …

  4. python - Using Null/None/Nil vs empty data types - Software …

    Aug 9, 2019 · I'm new to Python, coming from PHP. I've been looking through Python style guides & code examples, I've noticed the None data type is used where I wouldn't use it. I always …

  5. python - `var is None` vs `var == None` - Software Engineering …

    Jun 10, 2016 · Why do people prefer var is None over var == None when is can be used on few objects only?

  6. python - Purpose of `return self` from a class method? - Software ...

    Suffice it to say, returning self is the definitive OO way to craft class methods, but Python allows for multiple return values, tuples, lists, objects, primitives, or None. Chaining, as they put it, is …

  7. Type-hinting and accessing values that are not initialized in __init__ ...

    Oct 14, 2021 · A design in which the object changes it shape / available fields depending on state is generally not a good design. Your solutions in which you model the field as an Optional[int] …

  8. When should an argument be set to None in Python?

    Sep 10, 2020 · The focus of my question is on design. If I have an argument that can be None and it is passed between several functions until finally being used, which function should treat …

  9. python - Is it really correct to declare all instance attributes in ...

    Sep 24, 2017 · To me it seems like unnecessary cluttering to declare __init__ just for sake of calling parent __init__ and declare couple of parameters as None. Usually parse -ing functions …

  10. Why are there two ways to retrieve values from a dictionary in …

    Jan 15, 2024 · In Python there are basically two ways to get a value from a dictionary: dictionary ["key"] dictionary.get ("key") Is there any - maybe historical - reason for this behavior?