Replit database

how to use a specific word to get the content of that word in the replit database in python?

Using the Replit database:

from replit import db

db["word"] = "content"

print(db["word"]) # -> "content"
print(db.get("word")) # -> "content"

print(db.get("another word", "not found")) # -> "not found"

print(db.keys()) # -> ("word")

db.pop("word")

print(db.get("word", "not found")) # -> "not found"

Replit Database Tutorial

no, i want like this

db[“key”] = “”"
a=1
b=2
“”"

Then use print() to show the a of the “key” in the db

Do you mean like this?

db["a"] = 1
db["b"] = 2

print(db["a"]) # -> 1
print(db["b"]) # -> 2

Or like this?

db["key"] = {
	"a": 1,
	"b": 2
}
print(db["key"]["a"]) # -> 1
print(db["key"]["b"]) # -> 2
2 Likes

Can I only change the “a” content in the db key without change all key?

I’m not 100% clear on what you’re asking, but if I understand correctly, yes. Both the examples I gave you above will only change the content stored in a.

db["a"] = 0
db["b"] = 1

db["a"] = 1 # this is ONLY affects 'a', nothing else is changed

print(db["a"]) # -> 1
print(db["b"]) # -> 1
db["key"]["a"] = 0
db["key"]["b"] = 1

db["key"]["a"] = 1 # this is ONLY affects 'a', 'a' being within 'key' (if you had db["a"] aswell, that would not be changed for example), nothing else is changed

print(db["key"]["a"]) # -> 1
print(db["key"]["b"]) # -> 1
2 Likes

your answer is what I need, thanks :smiley:, I’m just asking more :sweat_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.