Ask coding questions

← Back to all posts
How to use replit database
CodingEssence (133)

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?

MrVoo (96)

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

Coder100 (18925)

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

SixBeeps (5348)

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"] )