woah, what are you trying to do there?

  • 3
    What? You can declare variables in Python..
  • 4
    @TheVariant Only when you assign it too. The nearest thing to do that is:
    x = None

    but there is no such thing as:
    int x;
  • 3
    Python 3 has

    x: int
  • 4
    @zchfvy Nice to see, that someone actually knows about this nice feature.

    I use it frequently to keep track of types myself and help my texteditor with autocompletion.

    However, even if the statements work in python, it apparently has no effect, since it doesn't declare the variable.

    In general the ": <type>" is only an annotation in python and needs python 3.6+ for it to throw no errors (my rPi for example doesn't have the required version).
  • 3

    Ahh, interesting. I never actually checked how these unassigned variables behave.
    I just assumed they would be 'None' or some equivalent.
  • 2
    @zchfvy I neither checked it before.
    I also only knew that you can use them in your code, but actually do nothing to your code other than adding the annotation.

    You can use them, but nobody is required to follow them if you e.g. have them as function-parameters. Python does no type-checks by itself.
  • 1
    @LinusCDE oh you mean initializing a variable, sorry, was confused when you said declaring
  • 0
    @TheVariant Yeah. It's more academic but declaring and initializing are two completly different things in most programing languages.
Your Job Suck?
Get a Better Job
Add Comment