** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
Suppose you want to choose two from A, B, and C.
multiple_choice
choose_two = ('A', 'B', 'C')
#Prepare an empty list
answer = []
#Suppose you select A and C
answer.append('A')
answer.append('C')
print('Choise from this.', choose_two)
print('Your answer is', answer)
result
Choise from this. ('A', 'B', 'C')
Your answer is ['A', 'C']
If you create a list of choose_two
, the options may be rewritten later.
If you make it a tuple, you will get an error if you accidentally write the code to tamper with choose_two
itself.
Helps prevent bugs.
Recommended Posts