|
||||||
| Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
| Sponsored Links |
|
|
|
|||||
|
In Python it's called "lists".
You can access the lists using the index-operators, []. Lists starts at zero (0) like arrays, and they work almost in the same way. So if you want to get the first element in the list do this [0], the next [1] and so on. You can also use more advanced operators and do like this [0:2] which will return the two first elements in the list like a new list - and if you don't want the first element as a f.ex. string you can get it as a list like this [0:1]. You can also access it both ways using [-x] or [-x:-x], etc. Now you're probably confused if you don't know to all this, let's see an example: Code:
l = ["apple", "banana", "orange"] l[0] # Returns "apple" l[1] # Returns "banana" l[0:1] # Returns ["apple"] l[0:2] # Returns ["apple", "banana"] l[1:3] # Returns ["banana", "orange"] |
|
|||||
|
Thank you dear vOid,
I must say that sometimes when I print the return value of the program, it shows " zeros((0,),'i') " I know that it is a part of numarray module, but I don't find a way to recieve the result as a string. the tostring() method of array does not work here. Can you please help me? Thank you very much. |
|
|||||
|
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'> 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'> |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Splitting Strings with Empty Separator (Python) | Matt | Python | 3 | 05-18-2007 01:27 PM |
| Python 2D array question | annannienann | Python | 3 | 04-23-2007 05:36 PM |
| Python Collection | reachpradeep | Python | 1 | 03-03-2007 03:50 PM |
| Arrays | clookid | PHP Tutorials | 1 | 01-11-2007 09:30 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |