top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is significance of Tuples in Python? Can someone please explain with example

+2 votes
939 views
What is significance of Tuples in Python? Can someone please explain with example
posted Nov 6, 2014 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The only difference is that tuples can't be changed i.e., tuples are immutable.

Example

tup = ('query', 'home');

The empty tuple is written as two parentheses containing nothing:

tup = ();

To write a tuple containing a single value you have to include a comma even if it has only one value.

tup = (10,);

Like string indices, tuple indices start at 0, and tuples can be sliced, concatenated and so on.

Accessing Values in Tuples:
To access values in tuple, use the square brackets for slicing along with the index

#!/usr/bin/python

tup = ('query', 'home'); 
print "tup[0]: ", tup[0]

Output
tup1[0]:  query
answer Nov 7, 2014 by Salil Agrawal
Similar Questions
+5 votes

I gone through the RFC4006 but didnt get the context of below paragraph

   Certain applications require multiple credit-control sub-sessions.
   These applications would send messages with a constant Session-Id
   AVP, but with a different CC-Sub-Session-Id AVP.  If several credit
   sub-sessions will be used, all sub-sessions MUST be closed separately
   before the main session is closed so that units per sub-session may
   be reported.  The absence of this AVP implies that no sub-sessions
   are in use.

But here my question is
1. What could be the types of Multiple credit-ontrol Sub-session?
2. How can we include different cc-sub-session-ID for each sub-session, please give me an example with message structure using CCR message.

...