Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python Python help

hellocode123

New Coder
I have this code:
Code:
object = {
    "date": "['2000-05-23']"
}

I just want to retrieve the inside string of 2000-05-23. But when I print(object["date"][0]) it prints the first character "[". How do I get it to just retrieve the date?
 
Python dicts work as a key value pair. As suggested by simong1993 will give you the value
Here are some examples of acessing dict keys and values

Python:
object = {
    'man': 'tom',
    'woman': 'jane',
    'child': 'pete'
}

print('# print a dict.')
print(object)

print()
print('# single object using known key')
print(object['man'])

print()
print('# print dict values')
for value in object.values():
    print(value)

print()
print('# print dict keys')
for key in object.keys():
    print(key)

print()
print('# print dict key and value')
for key, value in object.items():
    print(f'{key}: {value}')

print()
print('# print object values using key')
for key in object:
    print(object[key])

output
Code:
# print a dict.
{'man': 'tom', 'woman': 'jane', 'child': 'pete'}

# single object using known key
tom

# print dict values
tom
jane
pete

# print dict keys
man
woman
child

# print dict key and value
man: tom
woman: jane
child: pete

# print object values using key
tom
jane
pete
 
Last edited:
Back
Top Bottom