[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-697980-105":3,"doc-detail-697980-en":80,"detail-sidebar-cat-0-en-105":114,"doc-similar-697980":162},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","tuples-and-dictionaries-introduction-to-tuples","TUPLES AND DICTIONARIES - Introduction to Tuples","","This section introduces tuples and explains how to create them using parentheses and commas, how indexing and slicing work, and how tuples handle single-element cases with a trailing comma. It highlights tuple immutability and contrasts it with list mutability inside tuples, showing that while tuple elements cannot be reassigned, mutable elements can be modified. Examples demonstrate access, errors from out-of-range indices, and tuple operations such as concatenation, repetition, membership, and slicing.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/tuples-and-dictionaries-introduction-to-tuples/697980/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/tuples-and-dictionaries-introduction-to-tuples/697980.png","ImageObject",300,407,{"name":42,"@type":43},"Theodore","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-15","2026-11-12",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"How is a tuple defined and how are its elements separated?","Question",{"text":62,"@type":63},"A tuple is an ordered sequence of elements, typically enclosed in parentheses, with elements separated by commas.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"Why does assigning a single element to a tuple require a trailing comma?",{"text":67,"@type":63},"If a single element is assigned without a comma, Python treats it as an integer; adding a comma creates a one-element tuple.",{"name":69,"@type":60,"acceptedAnswer":70},"Can tuple elements be changed after creation?",{"text":71,"@type":63},"A tuple is immutable, so direct element reassignment raises an error. However, if an element is a mutable type (like a list), that mutable element can be modified.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},697980,1794446564,{"code":4,"msg":81,"data":82},"success",{"doc_id":78,"user_id":83,"nickname":42,"user_avatar":84,"doc_module":4,"category_id":85,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":86,"file_id":87,"file_url":88,"file_type":89,"file_size":90,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":91,"language":92,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":93,"faqs":94,"seo_title":95,"seo_description":12,"update_tm":79,"read_time":96,"preview_page_count":33,"preview_urls":97},7971461740886,"https://ap-avatar.wpscdn.com/davatar_3d24733baf745e90a7e4bdd5f77d97b2",6,"# TUPLES AND DICTIONARIES\n\n## 10.1 INTRODUCTION TO TUPLES\n\nA tuple is an ordered sequence of elements of differentdata types,such as integer,float,string,list or even atuple.Elements of a tuple are enclosed in parenthesis(round brackets)and are separated by commas.Like listand string,elements of a tuple can be accessed usingindex values,starting from 0.  \nExample 10.1  \n\\#tuplel is the tuple of integers>>>tuplel =(1,2,3,4,5)>>>tuplel  \n(1,2,3,4,5)  \n\\#tuple2 is the tuple of mixed data types>>>tuple2 =('Economics',87,'Accountancy',89.6)>>>tuple2  \n('Economics',87,'Accountancy',89.6)\\#tuple3 is the tuple with list as an element>>>tuple3 =(10,20,30,[40,50])>>>tuple3  \n(10,20,30,[40,50])  \n\\#tuple4 is the tuple with tuple as an element>>>tuple4 =(1,2,3,4,5,(10,20))>>>tuple4  \n(1,2,3,4,5,(10,20))  \nIf there is only a single element in a tuple then theelement should be followed by a comma.If we assign thevalue without comma it is treated as integer.It shouldbe noted that a sequence without parenthesis is treatedas tuple by default.  \n\\#incorrect way of assigning single element to\\#tuple  \n\\#tuple5 is assigned a single element>>>tuple5 =(20)  \n1112BCH10  \n“Computers are to computingas instruments are to music.Software is the score whoseinterpretations amplifes ourreach and lifts our spirits  \nLeonardo daVincicalled musicthe shaping of the invisible,andhis phrase is even more apt as adescription ofsoftware.”  \n-AKay  \nIn this chapter  \n》 Introduction toTuples  \n》Tuple Operations  \n》Tuple Methods andBuilt-in Functions  \n》Tuple Assignment  \n》Nested Tuples  \n》Tuple Handling  \n》 Introduction toDictionaries  \n》 Dictionaries areMutable  \n》Dictionary  \nOperations  \n》Traversing a  \nDictionary  \n》Dictionary Methodsand Built-inFunctions  \n》Manipulating  \nDictionaries  \nWe generally use listto store elements ofthe same data typeswhereas we use tuplesto store elements ofdifferent data types.  \n>>>tuple5  \n20  \n>>>type(tuple5)  \\#tuple5 is not of type tuple\u003Cclass 'int'>\\#it is treated as integer  \n\\#Correct Way of assigning single element to\\#tuple  \n\\#tuple5 is assigned a single element  \n>>>tuple5 =(20,)\\#element followed by comma>>>tuple5  \n(20,)  \n>>>type(tuple5)\\#tuple5 is of type tuple\u003Cclass 'tuple'>  \n\\#a sequence without parentheses is treated as\\#tuple by default>>>seq =1,2,3\\#comma separated elements>>>type(seq)\\#treated as tuple\u003Cclass 'tuple¹>>>>print(seq)\\#seq is a tuple  \n(1,2,3)  \n### 10.1.1 Accessing Elements in a Tuple\n\nElements of a tuple can be accessed in the same way asa list or string using indexing and slicing.  \n>>>tuple1 =(2,4,6,8,10,12)\\#initializes a tuple tuple1  \n\\#returns the first element of tuple1>>>tuple1[0]2  \n\\#returns fourth element of tuple1>>>tuplel[3]8  \n\\#returns error as index is out of range>>>tuple1[15]  \nIndexError:tuple index out of range  \n\\#an expression resulting in an integer index>>>tuple1[1+4]12  \n\\#returns first element from right>>>tuple1[-1]12  \n### 10.1.2 Tuple is Immutable\n\nTuple is an immutable data type.It means that theelements of a tuple cannot be changed after it has beencreated.An attempt to do this would lead to an error.  \n>>>tuple1 =(1,2,3,4,5)  \n>>>tuple1[4]=10  \nTypeError:'tuple'object does not support  \nitem assignment  \n√List is mutable buttuple is immutable.So iterating througha tuple is faster ascompared to a list.  \nHowever an element of a tuple may be of mutable type,  \ne.g.,a list.  \n\\#4th element of the tuple2 is a list>>>tuple2 =(1,2,3,[8,9])  \n\\#modify the list element of the tuple tuple2>>>tuple2[3][1]=10  \n√If we have data thatdoes not changethen storing thisdata in a tuple willmake sure thatit is not changedaccidentally.  \n\\#modification is reflected in tuple2>>>tuple2  \n(1,2,3,[8,10])  \n## 10.2 TUPLE OPERATIONS\n\n### 10.2.1 Concatenation\n\nPython allows us to join tuples using concatenationoperator depicted by symbol+.We can also create a newtuple which contains the result of this concatenationoperation.  \n>>>tuplel =(1,3,5,7,9)>>>tuple2 =(2,4,6,8,10)>>>tuplel +tuple2\\#c","cbCaidslmt7fleah","https://ap.wps.com/l/cbCaidslmt7fleah","pdf",2255804,22,"English","# 10.1 Introduction to Tuples\n## 10.1.1 Accessing Elements in a Tuple\n## 10.1.2 Tuple is Immutable\n# 10.2 Tuple Operations\n## 10.2.1 Concatenation\n## 10.2.2 Repetition\n## 10.2.3 Membership\n## 10.2.4 Slicing\n# Introduction to Dictionaries","[{\"question\":\"How is a tuple defined and how are its elements separated?\",\"answer\":\"A tuple is an ordered sequence of elements, typically enclosed in parentheses, with elements separated by commas.\"},{\"question\":\"Why does assigning a single element to a tuple require a trailing comma?\",\"answer\":\"If a single element is assigned without a comma, Python treats it as an integer; adding a comma creates a one-element tuple.\"},{\"question\":\"Can tuple elements be changed after creation?\",\"answer\":\"A tuple is immutable, so direct element reassignment raises an error. However, if an element is a mutable type (like a list), that mutable element can be modified.\"}]","TUPLES AND DICTIONARIES - Introduction to Tuples | PDF",55,[98,102,106,110],{"page_no":22,"url":99,"width":100,"height":101},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/f5bf41d42e12b5cde1884dd865eb7f32.webp",983,1295,{"page_no":26,"url":103,"width":104,"height":105},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/dfc2ddd1ab193e8de93807a9808b537d.webp",982,1294,{"page_no":30,"url":107,"width":108,"height":109},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/2025d051c54bfd566e26e3215bbaf949.webp",981,1293,{"page_no":33,"url":111,"width":112,"height":113},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/5f39b8257b2c77eaa49197a6eec6ef61.webp",980,1291,{"code":4,"msg":81,"data":115},[116,120,124,128,133,136,141,146,151,154,158],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":117,"show_sort_weight":118,"slug":119},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":121,"show_sort_weight":122,"slug":123},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":125,"show_sort_weight":126,"slug":127},"Exam",70,"exam",{"id":129,"doc_module":4,"doc_module_name":25,"category_name":130,"show_sort_weight":131,"slug":132},5,"Comic",60,"comic",{"id":85,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":134,"slug":135},50,"technology",{"id":137,"doc_module":4,"doc_module_name":25,"category_name":138,"show_sort_weight":139,"slug":140},7,"Healthcare",40,"healthcare",{"id":142,"doc_module":4,"doc_module_name":25,"category_name":143,"show_sort_weight":144,"slug":145},8,"Research & Report",30,"research-report",{"id":147,"doc_module":4,"doc_module_name":25,"category_name":148,"show_sort_weight":149,"slug":150},9,"Religion & Spirituality",20,"religion-spirituality",{"id":149,"doc_module":4,"doc_module_name":25,"category_name":152,"show_sort_weight":149,"slug":153},"World Cup","world-cup",{"id":155,"doc_module":4,"doc_module_name":25,"category_name":156,"show_sort_weight":155,"slug":157},10,"Lifestyle","lifestyle",{"id":159,"doc_module":4,"doc_module_name":25,"category_name":160,"show_sort_weight":129,"slug":161},19,"General","general",{"list":163,"token":11},[164,170,176,182,188,194,199,205,211,217],{"doc_id":165,"doc_title":166,"file_type":89,"home_preview_img_url":167,"slug":168,"view_count":129,"category_name":29,"create_tm":169},685778,"1-Tuples","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203953/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=V40tJyT8f0GSisVbs6j7hIptW38%3D","1-tuples",1794018230,{"doc_id":171,"doc_title":172,"file_type":89,"home_preview_img_url":173,"slug":174,"view_count":33,"category_name":29,"create_tm":175},685780,"Tuple in Python - Lecture 2","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203975/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=7ZYEjXilEcQW%2F%2Bz9T6RIcxWclkc%3D","tuple-in-python-lecture-2",1794018232,{"doc_id":177,"doc_title":178,"file_type":89,"home_preview_img_url":179,"slug":180,"view_count":137,"category_name":29,"create_tm":181},697976,"6.0001 Lecture 5 - Tuples, Lists, Aliasing, Mutability, Cloning","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146768/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=ygKbq1PhJBqw%2BIPbRYzWxIactbo%3D","60001-lecture-5-tuples-lists-aliasing-mutability-cloning",1794446554,{"doc_id":183,"doc_title":184,"file_type":89,"home_preview_img_url":185,"slug":186,"view_count":85,"category_name":29,"create_tm":187},697978,"Lecture 4: Tuples, List Slicing, List Comprehension, Strings","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146771/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=7GbhiozmT2zTg6HcPsKJTMYZbTw%3D","lecture-4-tuples-list-slicing-list-comprehension-strings",1794446559,{"doc_id":189,"doc_title":190,"file_type":89,"home_preview_img_url":191,"slug":192,"view_count":137,"category_name":29,"create_tm":193},685773,"Lists and Tuples - Chapter 7 - Programming Concepts","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203784/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=Vd0FWmNU3VFLxR7eV4JucxmqDgw%3D","lists-and-tuples-chapter-7-programming-concepts",1794018219,{"doc_id":195,"doc_title":196,"file_type":89,"home_preview_img_url":197,"slug":198,"view_count":30,"category_name":29,"create_tm":193},685772,"UNIT-IV - LIST, TUPLES, DICTIONARIES - Problem Solving and Python Programming","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203776/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=X8eNO%2FdM0MDxTlY4JdfvFqBkZps%3D","unit-iv-list-tuples-dictionaries-problem-solving-and-python-programming",{"doc_id":200,"doc_title":201,"file_type":89,"home_preview_img_url":202,"slug":203,"view_count":85,"category_name":29,"create_tm":204},685629,"Chapter 2: Lists, Arrays and Dictionaries","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999084017/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=UO5pbJHC1P7HLyS%2FvP0G%2FCiLf58%3D","chapter-2-lists-arrays-and-dictionaries",1794016092,{"doc_id":206,"doc_title":207,"file_type":89,"home_preview_img_url":208,"slug":209,"view_count":129,"category_name":29,"create_tm":210},685631,"Introduction to List - List Operations - Traversing a List - List Methods and Built-in Functions","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999084036/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=O5RB9ct8r6dUIe2kIGoRqhfP2E4%3D","introduction-to-list-list-operations-traversing-a-list-list-methods-and-built-in-functions",1794016095,{"doc_id":212,"doc_title":213,"file_type":89,"home_preview_img_url":214,"slug":215,"view_count":129,"category_name":29,"create_tm":216},685779,"Topic 6 - Lists, Sets, Tuples, Dictionaries","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203959/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=X5FWswqZ2z3yvTQsnItr6MbFuS0%3D","topic-6-lists-sets-tuples-dictionaries",1794018231,{"doc_id":218,"doc_title":219,"file_type":89,"home_preview_img_url":220,"slug":221,"view_count":85,"category_name":29,"create_tm":222},685634,"Python Collections - Arrays - List and Function","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999084045/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111099&Signature=vAWA%2BRM8wYPxkqvqZUsfpoi6khY%3D","python-collections-arrays-list-and-function",1794016101]