I am out of trial and error again Lists
MRAB
python at mrabarnett.plus.com
Fri Oct 24 20:20:53 EDT 2014
On 2014-10-25 00:57, Seymore4Head wrote:
[snip]
> Wait! I don't get it.
> name="012"
> b=list(range(3))
> print (name[1])
> print (b[1])
> 1
> 1
>
> I forgot the b
>
If you print the int 1, you'll see:
1
If you print the string "1", you'll see:
1
Normally you want it to print only the characters of the string. Think
how annoying it would be if every time you printed a string it appeared
in quotes:
>>> print("Hello world!")
'Hello world!'
How could you print just the text:
Hello world!
No, it's better that it prints the characters of the string.
One function you can use is repr:
x = 1
y = "1"
print(repr(x))
print(repr(y))
This will print:
1
'1'
OK, now it's clear that x is an int and y is a string.
More information about the Python-list
mailing list