{"id":16896,"date":"2021-08-17T08:48:02","date_gmt":"2021-08-17T03:18:02","guid":{"rendered":"https:\/\/python-programs.com\/?p=16896"},"modified":"2021-11-22T18:37:23","modified_gmt":"2021-11-22T13:07:23","slug":"python-program-for-comma-separated-string-to-tuple","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-comma-separated-string-to-tuple\/","title":{"rendered":"Python Program for Comma-separated String to Tuple"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Shuffle Elements of a Tuple<\/a>
\nTuple in Python:<\/strong><\/p>\n

A tuple is an immutable list of objects. That means the elements of a tuple cannot be modified or changed while the program is running.<\/p>\n

split() function:<\/strong><\/p>\n

Syntax:<\/strong> input string.split(seperator=None, maxsplit=-1)<\/strong><\/p>\n

It delimits the string with the separator and returns a list of words from it. The maxsplit parameter specifies the maximum number of splits that can be performed. If it is -1 or not specified, all possible splits are performed.<\/p>\n

Example:\u00a0 Given string =\u00a0 ‘hello btechgeeks goodmorning’.split()<\/p>\n

Output : [‘hello’, ‘btechgeeks’, ‘goodmorning’ ]<\/p>\n

Given a string and the task is to find a tuple with a comma-separated string.<\/p>\n

Examples:<\/strong><\/p>\n

Example 1:<\/strong><\/p>\n

Input:\u00a0<\/strong><\/p>\n

Given String = 'good, morning, btechgeeks'     (static input)<\/pre>\n

Output:<\/strong><\/p>\n

Given input String =  good, morning, btechgeeks\r\nA tuple with comma-separated string is :  ('good', ' morning', ' btechgeeks')<\/pre>\n

Example 2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = hello, btechgeeks, 123        (user input)<\/pre>\n

Output:<\/strong><\/p>\n

A tuple with comma-separated string is : ('hello', ' btechgeeks', ' 123')<\/pre>\n

Program for Comma-separated String to Tuple<\/h2>\n

Below are the ways to find a tuple with a comma-separated string.<\/p>\n