Most people get some problems when programming python, but most of the time the problem isin’t the machine, but who is behind it. Today we will check this out, the most common mistakes when programming python.
1- Setting variables incorrectly
python has a whole different method of setting variables, well, it will still works but not that good, normally in some languages like C you need to set up wich kind of variable it will hold, if is a number, a string, a floating point, etc. Like so:
# wrong, please dont do this!!! integer = int(100) list = list([1,2,3,4]) float = float(1.5) # ... # correct python code! integer = 100 list = [1,2,3,4] float = 1.5 # ...
2- Forgetting parentesis to execute function
most python funcions applications will need parentesis, except if will be a future call, for example:
# normal function, ok by now... printCopycat() print("Copycat!") return "Copycat" # will run with no errors, but also does not execute the code! printCopycat str = printCopycat # now runs correctly str() # because str = printCopycat was declared bla = printCopycat()
3- string + string (yeah…)
Well lets say you did set variables incorrectly, Congrats! now you sadly made the mistake of setting X as a string of 2!!! so what now?
x = str(2) # the deadly mistake print(x + x) # should be 4 but will print 22 XD # even worst... print(x + 10) # should be 12 but actually prints error code.