Let me keep this brief, I like the way javascript handles arrays. Specifically, as follows:
var myDB = new Array();
myDB[0] = "";
myDB[1] = "another entry";
The reason I like this, and why I am having troubles is that I am trying to replicate this in python. The reason I want to replicate this in python is because I am working on a psuedo operating system, and would like to allow users to add new entries to the variable that don’t yet exist. If I could make it work, this is what it would look like:
myDB = #Array
userAdd = input('what would you like to add to the array?')
myDB[myDB.length + 1] = userAdd
I hope this makes sense.
To be a little more clear – I am wanting this to act as a sort of session memory. The only way I can realistically think to make things work currently is to limit users to the amount of memory spaces I create as as many variables allocated to it, such as follows:
myDB0 = ''
myDB1 = ''
myDB2 = ''
myDB3 = ''
myDB4 = ''
editDB = input('what slot would you like to change?')
if editDB == '1':
addMem = input('what would you like it to be?')
myDB0 = addMem
#And et cetera for each memory space
Yes, the python code wasn’t valid, but I guess that was sort of my point lol – I wasn’t sure what the appropriate code would be for that type of formatting.
Of course, this is not good python. Just use my_db.append(...) instead of my_db[i] = ...
my_db = []
user_add = input('what would you like to add to the array?')
my_db.append(user_add)
To edit,
try:
index = int(input('what slot would you like to change'))
except ValueError:
print('invalid input')
else:
if 0 <= index < len(my_db):
item = input('what would you like it to be?')
my_db[index] = item
else:
print('slot does not exist')