Creating an integer in robot mesh python

Could someone send an example of creating an interger? I know how to make a variable, I usually say (name of variable) = None
But when I make something equal to a number
Distance = 1
All it does is make distance ==1 but it’s just a variable and not an integer. Please help on making something an integer. It’s easier with cpp because you can say-
int Distance = 1


I am pretty sure just setting something to a number allocates whatever memory it needs and classifies it as a (whatever number type). So your code technically does make an integer. An integer is a type of variable.
So, you could argue that it is easier with Python (I still prefer C++).


In python, variables become initialized whenever you use them in the code. (i.e. you don’t have to “create” or initialize the integer, it will create its self)

EDIT: Sniped by @trontech569, his explanation was better.


What’s the difference between making distance equal to one, and creating an integer called distance? What are you trying to do that’s not working with this/how is this different from the behaviour you were expecting?


What I’m trying to do is something like this
Distance = 1
While true:
If joystick.buttonA.pressing():
Distance = Distance + 1

This line should be that whenever I press A, the distance variable should go from 1-2 and every time I press it, the variable increases by 1, but this isnt working and instead it’s just saying that the variable distance is LITERALLY equal to Distance + 1

That snippet looks okay to me - could you post the exact code you’re having trouble with (remembering to wrap it in [code]...[/code] tags for formatting)?

Also, I’m not quite sure what you mean by

distance is LITERALLY equal to Distance + 1

could you expand on this?


You might need to use some kind of sleep function, so it only has enough time to add the number once. like this:

Distance = 1
while True:
     if joystick.buttonA.pressing():
         Distance = Distance + 1 #Distance += 1 does the same thing

Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.


Reminder, that if you use a variable, always declare it ahead of time and set it equal to SOME value. An accidental usage when it’s undeclared can cause undesired results.