You Are Here:

Community: Developer Discussion Boards

#1 Old QUERY - 2008-10-04, 14:40

Join Date: Oct 2008
Posts: 12
kar2905
Offline
Registered User
How do we declare an array..
if i want to use it in a for loop.. how to..

eg..
for i int range(0,6):
t[i]=i

it gives an error.
it says t is not defined...

pls help....
Reply With Quote

#2 Old Re: QUERY - 2008-10-04, 14:42

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Code:
t=[] #An empty array
for i in range(0,6):
   t.append(i)
#In the end, t will be [0,1,2,3,4,5]
Reply With Quote

#3 Old Re: QUERY - 2008-10-04, 15:01

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by kar2905 View Post
How do we declare an array..
if i want to use it in a for loop.. how to..

eg..
for i int range(0,6):
t[i]=i

it gives an error.
it says t is not defined...

pls help....
hi kar2905

i feel you want to know about syntax issues in python then please have a look at this link on my website.
the website is now going through a renovation there are lots and lots syntax issues i am going to cover.


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#4 Old Re: QUERY - 2008-10-04, 15:18

Join Date: Oct 2008
Posts: 12
kar2905
Offline
Registered User
thanks...
for strings how do we do it..
eg
a=["","",""]
a[0]=["ka",karr"]
a[1]=["a","b"]
a[2]=["db","gh"]
it works ... but it has some some shortcomings which i discovered while making an application.

like u said
a=[]
then what should we do
Reply With Quote

#5 Old Re: QUERY - 2008-10-04, 15:24

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Quote:
Originally Posted by kar2905 View Post
thanks...
for strings how do we do it..
eg
a=["","",""]
a[0]=["ka",karr"]
a[1]=["a","b"]
a[2]=["db","gh"]
it works ... but it has some some shortcomings which i discovered while making an application.

like u said
a=[]
then what should we do
What exactly do you want to do with this? In other words, how should the array "a" look in the end?

Also, here's a pretty good tutorial about Python arrays (also known as lists):
http://effbot.org/zone/python-list.htm
Reply With Quote

#6 Old Re: QUERY - 2008-10-04, 15:25

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by kar2905 View Post
thanks...
for strings how do we do it..
eg
a=["","",""]
a[0]=["ka",karr"]
a[1]=["a","b"]
a[2]=["db","gh"]
it works ... but it has some some shortcomings which i discovered while making an application.

like u said
a=[]
then what should we do
hi kar2905

a = []
is a empty list and is very useful in some cases. You can add whatever content you want to add in it.
like in bogdans post he has clearly adding the numbers 0 to 6 in the empty list t.

Hope you got it
Gaba88


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#7 Old Re: QUERY - 2008-10-04, 17:50

Join Date: Oct 2008
Posts: 12
kar2905
Offline
Registered User
thanks..
i want the array a to be 2d array of strings.
in which a[0],a[1],a[2] store a list.
a stores all these .
is there any other method to implement it.

i want the array a to store
a=["ka""kar","a""b","c"]
a[0] has ka and kar
and so on..
Last edited by kar2905 : 2008-10-04 at 18:01.
Reply With Quote

#8 Old Re: QUERY - 2008-10-04, 17:59

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Well you can use the append method to add items to the end of the array when needed. You can use assignment
(a[0]="something", for example) to modify elements that are already in the array according to their index. And you can use the insert method to insert items at a certain position in the array.
Reply With Quote

#9 Old Re: QUERY - 2008-10-04, 18:05

Join Date: Oct 2008
Posts: 12
kar2905
Offline
Registered User
can i append more than one string at a time using append.
eg.
a.append("kartik","kar")
it gives an error
so how to make a[2] store both kartik and kar
do you mean that I should use
a.append("kartik")
then use a.insert(position,"kar")
Reply With Quote

#10 Old Re: QUERY - 2008-10-04, 18:11

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
If you want an element of the array to be an array, simply append an array:
Code:
a.append(["kartik","kar"])
If you want to append more than one item at a time, that is not possible.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL query Issue kamaljaiswal General Symbian C++ 4 2008-06-25 10:17
I cannot send query string to the servlet raghda Mobile Java Networking & Messaging & Security 1 2007-09-10 08:23
Dialog query!!! Trojan General Symbian C++ 3 2006-10-13 10:36
Multiline Query in 3rd edition sdk parag_purkar Symbian User Interface 1 2006-09-26 04:54
Query problem samweb General Symbian C++ 2 2004-07-05 11:03

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia