Question About Creating Lists

7stud bbxx789_05ss at yahoo.com
Thu Apr 12 17:46:33 EDT 2007


On Apr 12, 3:29 pm, "Scott" <s_brosci... at comcast.net> wrote:
> I'm sorry if most of my question's seem "petty", but as I've said before, I
> need to know the petty just because I need to know.
>
> This question is more along the lines of just having you guys either agree
> or disgree with me, and if disagreeing to give the reasoning behind it, to
> further my understanding of lists.
>

Please forgo the psychological self analysis from your future posts.


> Am I safe in assuming that if the list your building contains number's it
> will be written as follows:
>
> >>>my_list = [1, 2, 3, 4, 5]
>
> But the minute you throw in something that's not a number it has to be
> written as:
>
> >>>my_list = [1, 2, 3, 4, 'five']
> >>> my_list
>
> [1, 2, 3, 4, 'five']
>
> Unless five was defined, then it could be written as:
>
> >>>five = 5
> >>>my_list = [1, 2, 3, 4, five]
> >>> my_list
>
> [1, 2, 3, 4, 5]
>
> Is this the correct way of thinking? Or am I, by thinking this is the case,
> crippling myself in my potential as a programmer

I don't think your question has anything to do with lists.  Maybe this
will help: there is a distinction between what are called "literals"
and "variables".  A variable is created like this:


num = 10

num is a variable.  It's called a variable because it's value can
"vary":

num = 20


On the other hand the value 10 cannot vary, so it is not a variable.
What is it?  It's called a "literal".  Here are some examples of
literals:

10       --- integer literal
3.5      --- float literal
"hello"  --- string literal

Literals are the values you can assign to variables.  Finally, any
name without quotes around it is variable and it refers to a value
which python will substitute in place of that name(that doesn't apply
to python keywords like if, while, etc.)







More information about the Python-list mailing list