简体   繁体   中英

Python Random Numbers using commas

I'm wondering how I can choose a random number from commas?

Here's an example configuration file:

{
    "number": 10,
    "thisisatest": "yes"
}

If I use the 'number' variable in my Python script, obviously it's 10 however I want to add more numbers than just 10, how would I do that?

Use a list:

{
    "number": [10, 20, 30, 40],
    "thisisatest": "yes"
}

and then use random.choice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM