View Single Post
  #4 (permalink)  
Old 06-20-2007, 09:54 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,635
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

You don't need any functions to convert the numeric value to a string, you can use simple type-casting. It's possible in Python because it's a very type-weak language, so everything is almost possible with types.

Here is an example to illustrate it (copy+pastet from the idle):
Code:
>>> my_num = 100
>>> my_str = my_num # will be 'int'
>>> type(my_num)
<type 'int'>
>>> type(my_str)
<type 'int'>
>>> my_str = str(my_num) # now it'll be 'str'
>>> type(my_str)
<type 'str'>
Here it's illustrated with a list:
Code:
>>> my_numbers = [1, 2, 3, 1000, 20000, 30000]
>>> type(my_numbers)
<type 'list'>
>>> type(my_numbers[0])
<type 'int'>
>>> type(str(my_numbers[0]))
<type 'str'>
>>> type(my_numbers[0:2])
<type 'list'>
>>> type(my_numbers[0:2][0])
<type 'int'>
>>> type(str(my_numbers[0:2][0]))
<type 'str'>
__________________
05-03-2007 - 11-13-2008
Reply With Quote