Assigning values to variables in Python works in a similar way to most programming languages.
2
to a variable named var
as follows:>>> var = 2 >>> var 2
var
as follows:>>> var = [2, 'spam', 'eggs'] >>> var [2, 'spam', 'eggs']
We can assign a new value to a list item using its index number (counting starts from 0). Assign a new value to the first list element:
>>> var ['ham', 'spam', 'eggs']
>>> a = 1 >>> b = 2 >>> a, b = b, a >>> a 2 >>> b 1
We assigned values to variables and Python list items. This section is by no means exhaustive; therefore, if you are struggling, please read Appendix B, Additional Online Resources, to find recommended Python tutorials.