Skip to content
Sign upLog in
← Back to Community

How to use replit database

Profile icon
CyberPy

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?

Voters
Profile icon
CyberPy
Comments
hotnewtop
Profile icon
MrVoo

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

Profile icon
Coder100

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
CyberPy

@Coder100
Ok thanks!

Profile icon
Coder100

np
mark as correct answer?

@CodingEssence

Profile icon
SixBeeps

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
CyberPy

@SixBeeps
thanks!