Skip to content
Sign upLog in
← Back to Community

How to use replit database

Profile icon

So I was creating a game, and I want to create a leaderboard for it, in python. So I just want to make sure, is this how you create keys in python for the replit database?:

db["Username"] = "CodingEssence"

We have to keep the quotation marks, right?

And are we allowed to use f strings as the name of the key?

For example, like this?:

db[f'{VariableHere}-{SecondVariableHere}'] = "Value" # Where the two variables in the curly brackets are variables

And how do we call them?

Profile icon
Profile icon

It doesn't work if you're making a console app

Profile icon

You can treat replit db as a dictionary!
So whatever you can do with a dictionary, you can do with replitdb.

  1. no, you don't need the quotation marks if you are referencing a variable:
var = "whatever" db[var] = "..."
  1. yes fstrings are allowed.

Next time, try those things out first before asking

Profile icon

Ok thanks!

Profile icon

mark as correct answer?


Profile icon

The key name is simply a string, so as long as it is a valid Python string that follows the DB's naming rules, you can use it. That means:

  • Yes, the quotation marks are necessary unless you are referring to a variable or function that will turn into a string
  • Yes, f-strings are okay
  • Yes, you can use string interpolations other than f-strings too

As for your last question, the db acts like an array:

print( db["amount-chickens"] )
Profile icon