|
||||||
| 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"]
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... |
|
|||||
|
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'>
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... |
![]() |
| 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 12:27 PM |
| Python 2D array question | annannienann | Python | 3 | 04-23-2007 04:36 PM |
| Python Collection | reachpradeep | Python | 1 | 03-03-2007 02:50 PM |
| Arrays | clookid | PHP Tutorials | 1 | 01-11-2007 08:30 PM |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| LogicKills | ........ | 20.00000 |
| sam | ........ | 20.00000 |
| gaylo565 | ........ | 18.00000 |
| |pH| | ........ | 15.00000 |
| WingedPanther | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 67%