← 返回 waymo 的题目列表Python DataClass: Implement Basic Key-Value Store with Get/Set
类型:online_judge
waymo
Implement a data class in Python that simulates get and set operations like a database. Requirements:
The data class should use a dictionary or another suitable data structure to store key-value pairs.
Implement the set(key, value) method to store a key-value pair in the data class.
Implement the get(key) method to return the value for a given key, or None if the key does not exist.
Assume the inputs for both keys and values are of string type.
Provide at least three test cases.
Example:
# Initialize the data class
obj = DataClass()
obj.set('a', '1')
print(obj.get('a')) # Should output '1'
print(obj.get('b')) # Should output None
Example
Input
set c 3
get c