Really simply, all I’m doing is adding a 0 to the front of the int called from the second() function when its below or equal to 9 so it displays in right when I call to the canvas. However, when I want to set the else function I can’t call secs = s; because I get an error that you can’t convert an int to a string. To get around this I did secs = “” + s; and my question is, is this just automatically doing the conversion for me when I append an int to a string? Should I be doing secs = str(s); instead or is that basically what’s happening here?
I just feel like I’m using a weird syntax and maybe someone more experienced can explain if if this is cool or I should avoid doing something like this?
Although i couldn’t say exactly what’s going on because im not looking at the reference, as you say it seems that the conversion is happening automatically because you are including a string type by including “0”, and my guess is the compiler treats everything else after in the same way is a string type. Whereas without the inclusion of the quotation marks all it sees is your s variable which is an int, which needs to be cast to a string first and it has no other instruction to tell it otherwise. So your code looks adequate. Now I’m not sure about performance related issues with this approach, but as you’re only dealing with one var it should be fine.
So alternatively you can cast to string or you can pass it through another variable which itself is the cast version of the s variable. Though that seems a bit redundant if you have the cast to string method.
" …and converts from primitive datatypes into the String datatype if necessary."
Nice! I wouldn’t have expected that to be on the addition page, but that answers my questions spot on and makes me feel more okay about not using str()
I think I’ll still need the if statement being I only want to add the zero when the second value is less than 10, but I totally forgot about nf() until you mentioned this. That would also work in this situation.
Is that what @GoToLoop was doing here as well with the colon? I wasn’t super sure with what was going on here either but assumed it was just another syntax for using a for loop that maybe was more optimized, but what do you mean by “making searching simple”?