简体   繁体   中英

Python: Random item from list combining only two

I'm making a slot machine program in Python and for some reason, the random selector wants to combine a known two elements.

    itmlist = random.choice(['banana', 'cherry', 'bar', 'seven', 'banana', 'cherry' 'banana', 'cherry', 'seven'])
    print itmlist

It shows up as "cherrybanana" every once in a while and I am really confused.

You miss a comma between 'cherry' and 'banana' near the end of the list.

Python concatenate the strings so it becomes 'cherrybanana'

itmlist = random.choice(['banana', 'cherry', 'bar', 'seven', 'banana', 'cherry' 'banana' , 'cherry', 'seven'])

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