I am out of trial and error again Lists

Seymore4Head Seymore4Head at Hotmail.invalid
Sat Oct 25 02:37:21 CEST 2014


On Sat, 25 Oct 2014 01:20:53 +0100, MRAB <python at mrabarnett.plus.com>
wrote:

>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.

Yes

x = 123
y = "123"
z = [1,2,3]
print(repr(x))
print(repr(y))
print(repr(z))
123
'123'
[1, 2, 3]

Thanks



More information about the Python-list mailing list