Is it a bug?

G

Gleb Belov

Hey everyone! I'm quite new to Python and equally new to newsgroups in
general, so apologies if this makes no sense.

Basically, I was just exploring Python "arrays" on my own, since I
come from C++. What I did was:
words = ["Hi!", "What's up?", "Bye!"]
print words
['Hi!', "What's up?", 'Bye!']

I have two questions:
1) Is it possible and if so, how do I access each individual element?
Are there any indexes and what is the syntax?
2) I just noticed that the first and the last words in the output are
enclosed in single quotes, and the middle one is enclosed in double
quotes. Is it a bug? If not, why does the output work that way?

Alright, thanks in advance for any replies and I hope I'll manage to
actually find this topic...
 
G

Gleb Belov

Gleb said:
Hey everyone! I'm quite new to Python and equally new to newsgroups in
general, so apologies if this makes no sense.
Basically, I was just exploring Python "arrays" on my own, since I
come from C++. What I did was:
words = ["Hi!", "What's up?", "Bye!"]
print words
['Hi!', "What's up?", 'Bye!']
I have two questions:
1) Is it possible and if so, how do I access each individual element?
Are there any indexes and what is the syntax?

For the first element:
2) I just noticed that the first and the last words in the output are
enclosed in single quotes, and the middle one is enclosed in double
quotes. Is it a bug? If not, why does the output work that way?

The output is valid python code. To represent with single quotes for the
second item, there would have to be a \ escape character for the
apostrophe.

Oh, thank you! That makes sense! Should have thought of the escape
character issue...
 
J

Jan Kaliszewski

25-08-2009 o 22:51:14 Gleb Belov said:
I have two questions:
1) Is it possible and if so, how do I access each individual element?
Are there any indexes and what is the syntax?

It's a 'Read-The-Friendly-Manual' question.

(hint: library reference - Built-in Types - ...)
 
A

Abhishek Mishra

Oops, missed out that... thanks

30-08-2009 o 06:10:46 Abhishek Mishra said:
The single quote \' is the culprit.
When you say  words = ["Hi", "Whats up", "Bye"] and try print words,
you get this -
['Hi', 'Whats up', 'Bye']

All double quotes converted to single ones. Now as for your input,
notice the single quote in What's
Now wrapping that word with single quotes won't be correct, so python
uses double quotes to avoid any quote completion errors.
But there's hardly much difference "foo" and 'foo' right? While in php
you can notice some difference.

Abhishek Mishra
http://ideamonk.blogspot.com

Hello,

You posted your message only to me -- and probably wanted to post it
to the list?

Cheers,
*j
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top