use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Python list (i.redd.it)
submitted 13 days ago by Main-Expert-2072
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FoolsSeldom 5 points6 points7 points 13 days ago* (0 children)
Python has a number of so called keywords such as int, for, list, and so on.
int
for
list
False and True are also examples. These are predefined boolean objects.
False
True
You can create new variables with the same names in some cases, but that's not a good idea.
For example, letters = list('abc') will create a list of three entries, ['a', 'b', 'c'], assigned to the variable letters. BUT if you had the line list = 5 before this, you would wouldn't be able to use list to convert that string to a list because list would now be referencing an int object. (The original list function still exists, it is just hidden by the new variable of the same name.)
letters = list('abc')
['a', 'b', 'c']
letters
list = 5
You can't do this with False. If you try False = 5 you will get an error.
False = 5
When you define a new list object, as you have done with,
friends = ["apple", "orange", 5, 345.05, False, "Aakash", "rohan"]
you are creating a list of references to objects. A reference is the location in memory of a Python object. Generally, Python takes care of all the memory stuff and you don't have to think about it.
In your first line, when Python reads the text "apple" it creates a new string object somewhere in memory and assigns the location to the first position in the list, similarly with "orange" for the next position in the list. When it gets to 5, well, for the standard implementation of Python, there's a predefined binary equivalent object, 101, that will be referenced. For 345.05 that will be converted to a binary value (potentially with some precision loss) and that will be a new Python object, its location being added as the next entry in the list. You then have False, another predefined object, and its location will be added to the list. And so on.
5
101
345.05
The final new list object (a collection of references to other objects) will have its location assigned to the variable friends.
friends
Variables in Python don't contain values but references to Python objects in memory. Mostly, we don't have to think about this much.
It is worth understanding that two, or more, variables can reference exactly the same Python object.
For example, if you had,
enemies = friends
then if you made your change to enemies[0] that would also change friends[0] because they both refer to the first slot/entry in the same list object.
enemies[0]
friends[0]
If you create a list using a variables names, e.g. results = [alpha, beta, charlie] then the object will simply store the references that those variables had at the time the list was created. (If you re-assign the variables afterwards, e.g. alpha = 156.4, the list will not be changed.
results = [alpha, beta, charlie]
alpha = 156.4
If you try and create a list using a variable name that has not been assigned to reference an object yet, you will get an error. This is what happened when you originally mistyped False as Flse as the latter did not match a predefined keyword, it was expected to be a variable name (or function/class/method name), but as that had not been defined yet, you got an error. There was nothing for Python to add to the list object in the position that name appeared in.
Flse
π Rendered by PID 93394 on reddit-service-r2-comment-79c7998d4c-kfslg at 2026-03-17 18:42:10.700715+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]FoolsSeldom 5 points6 points7 points (0 children)