{"id":12867,"date":"2021-10-01T11:00:31","date_gmt":"2021-10-01T05:30:31","guid":{"rendered":"https:\/\/python-programs.com\/?p=12867"},"modified":"2021-11-22T18:33:27","modified_gmt":"2021-11-22T13:03:27","slug":"python-program-to-find-the-size-of-a-tuple","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-size-of-a-tuple\/","title":{"rendered":"Python Program to Find the Size of a Tuple"},"content":{"rendered":"
Given a tuple, the task is to find the size of the given tuple in Python.<\/p>\n
Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to find the size of the given tuple in Python.<\/p>\n Our website provided core java programs examples with output<\/a> aid beginners and expert coders to test their knowledge gap and learn accordingly.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Given a tuple, the task is to find the size of the given tuple in Python. Examples: Example1: Input: Given tuple =(9, 11, 24, 19, 11, 23, 29, 23, 31) Output: The length of the given tuple (9, 11, 24, 19, 11, 23, 29, 23, 31) is [ 9 ] Example2: Input: Given tuple =(11, …<\/p>\nGiven tuple =(9, 11, 24, 19, 11, 23, 29, 23, 31)<\/pre>\n
The length of the given tuple (9, 11, 24, 19, 11, 23, 29, 23, 31) is [ 9 ]<\/pre>\n
Given tuple =(11, 19, 45, 13, 23, 32, 46, 18, 49,58, 53, 75, 11, 19, 93, 99, 85, 68, 24)<\/pre>\n
The length of the given tuple (11, 19, 45, 13, 23, 32, 46, 18, 49, 58, 53, 75, 11, 19, 93, 99, 85, 68, 24) is [ 19 ]<\/pre>\n
Program to Find the Size of a Tuple in Python<\/h2>\n
\n
Method #1: Using len() function<\/h3>\n
\n
# Give the tuple as static input and store it in a variable.\r\ngvntuple = (9, 11, 24, 19, 11, 23, 29, 23, 31)\r\n# Finding the size or length of a tuple is a rather simple task.\r\n# The number of objects in a tuple is represented by its size.\r\n# The syntax for determining the size is len ().\r\n# The number of elements\/objects in the tuple is returned by this function.\r\n# Calculate the len() using len() function and store it in a variable.\r\ntuplelength = len(gvntuple)\r\n# Print the length of the tuple.\r\nprint('The length of the given tuple', gvntuple, 'is [', tuplelength, ']')\r\n<\/pre>\n
The length of the given tuple (9, 11, 24, 19, 11, 23, 29, 23, 31) is [ 9 ]<\/pre>\n
Method #2: Using For loop<\/h3>\n
\n
# Give the tuple as static input and store it in a variable.\r\ngvntuple = (9, 11, 24, 19, 11, 23, 29, 23, 31)\r\n# Take a variable say tuplelength that calculates the given tuple\r\n# length and initializes its value to 0.\r\ntuplelength = 0\r\n# Loop through the elements of #Inside the For loop increment the value of tuplelength by 1.the tuple using For loop.\r\nfor elemen in gvntuple:\r\n # Inside the For loop increment the value of tuplelength by 1.\r\n tuplelength = tuplelength+1\r\n\r\n# Print the length of the tuple.\r\nprint('The length of the given tuple', gvntuple, 'is [', tuplelength, ']')\r\n<\/pre>\n
The length of the given tuple (9, 11, 24, 19, 11, 23, 29, 23, 31) is [ 9 ]<\/pre>\n
\n