Python Forum
declaring a new dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
declaring a new dictionary
#1
The question: How would we declare a new dictionary named myDict with one key-value pair where the key is "one" with a value of the integer of 1? You can either use single or double quotes, but ensure there are no spaces in your answer.

My solution:
myDict={"one":"1"}
This input is wrong and I am not sure why.
Reply
#2
the value is a string not an integer
Reply
#3
If you need an integer, use 1:

myDict={
    "one":1}
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020