Results 1 to 4 of 4

Thread: How to insert assessment into tuple?

  1. #1
    JacksonPerez is offline Banned
    Join Date
    Dec 2009
    Posts
    274
    Rep Power
    0

    Default How to insert assessment into tuple?

    I am BSC(I.t) student. I am learning python language. I have little bit knowledge of tuple, in one of my program I want to insert an extra value into each tuple. I know that tuples are immutable. I want to change e a new item next to it in a another currency like below:

    ('Soap', 8.00', '500.00')..I want to know how toinsert value into tuple? Thanks in advanced.

  2. #2
    ThompsonHarris is offline Senior Member
    Join Date
    Dec 2009
    Posts
    255
    Rep Power
    3

    Default

    You tried to make a new tuple from the old tuple. In this case you must use the collection. namedtuple generate a new type of object from the old type of object. With the collection. namedtuple class you can add extra value to each tuple.

  3. #3
    GonzalezBrown is offline Senior Member
    Join Date
    Dec 2009
    Posts
    260
    Rep Power
    3

    Default

    Try to understand following code which is given below it is helpful for you. You have to use cast that value to solve this problem. Firstly cast that value in to a list, insert the item, after that cast it back to a tuple.

    Code:
    x = ('Soap', '6.00', '500.00')
    x = list(x)
    x.insert(3, 'Lux')
    x = tuple(x)
    print a
    
    >> ('Product', '6.00', '500.00', 'Lux')

  4. #4
    LewisClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    260
    Rep Power
    3

    Default

    Try this code. In the following code you have to use += operator to do this. You can do this in following method.

    Code:
    thestups += ('1000.00',)
    After this you have to write following code.

    Code:
    bs=list(mystuple)
     bs.append("main file")
     as=tuple(bs)

Similar Threads

  1. Tuple variable in SQL
    By GonzalezBrown in forum Programming
    Replies: 1
    Last Post: 04-21-2010, 01:41 PM
  2. Insert a PC
    By Gannon Warner in forum Everything Else
    Replies: 7
    Last Post: 06-26-2009, 11:14 AM
  3. Insert a PC
    By Dewan Hauritz in forum Power Supply
    Replies: 2
    Last Post: 06-15-2009, 12:17 PM
  4. Insert a total row
    By fimanson in forum Everything Else
    Replies: 0
    Last Post: 06-23-2008, 03:45 PM
  5. Insert random text
    By hassik54 in forum Everything Else
    Replies: 0
    Last Post: 06-23-2008, 03:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48