Basic types and their use in Python<\/span><\/strong><\/p>\n Number data types store numeric values. Number objects are created when you assign a value to them. For example:<\/p>\n var1 <\/span>=<\/span> 1<\/span><\/p>\n var2 <\/span>=<\/span> 10<\/span><\/p>\n var3 = var1 + var2<\/span><\/p>\n print(var3)<\/span><\/p>\n Run code -> 11<\/span><\/p>\n Strings in Python are identified as a contiguous set of characters represented in the quotation marks.<\/span><\/p>\n str <\/span>=<\/span> ‘Hello World!’<\/span><\/p>\n print(str)<\/span><\/p>\n Run code-> Hello World!<\/span><\/p>\n Lists are the most versatile of Python’s compound data types. A list contains items separated by commas and enclosed within square brackets ([]).\u00a0<\/span>The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1.<\/span><\/p>\n list <\/span>=<\/span> [<\/span> ‘abcd’<\/span>,<\/span> 786<\/span> ,<\/span> 2.23<\/span>,<\/span> ‘john’<\/span>,<\/span> 70.2<\/span> ]<\/span><\/p>\n print(list)<\/span><\/p>\n print(list[0])<\/span><\/p>\n Run code:<\/span><\/p>\n [‘abcd’, 786, 2.23, ‘john’, 70.200000000000003]<\/p>\n abcd<\/p>\n A tuple consists of a number of values separated by commas.\u00a0<\/span>The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as\u00a0<\/span>read-only<\/strong>\u00a0lists.<\/span><\/p>\n tuple <\/span>=<\/span> (<\/span> ‘abcd’<\/span>,<\/span> 786<\/span> ,<\/span> 2.23<\/span>,<\/span> ‘john’<\/span>,<\/span> 70.2<\/span> )<\/span><\/p>\n print(tuple)<\/span><\/p>\n print(tuple[0])<\/span><\/p>\n Run code:<\/span><\/p>\n (‘abcd’, 786, 2.23, ‘john’, 70.200000000000003)<\/p>\n abcd<\/p>\n They work like associative arrays or hashes found in Perl and consist of key-value pairs.\u00a0<\/span>Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]).<\/span><\/p>\n dict <\/span>=<\/span> {}<\/span><\/p>\n dict<\/span>[<\/span>‘one’<\/span>]<\/span> =<\/span> “This is one”<\/span><\/p>\n dict<\/span>[<\/span>2<\/span>]<\/span> =<\/span> “This is two”<\/span><\/p>\n print<\/span> dict<\/span>[<\/span>‘one’<\/span>]<\/span><\/p>\n print<\/span> dict<\/span>[<\/span>2<\/span>]<\/span><\/p>\n Run code:<\/span><\/p>\n This is one<\/p>\n This is two<\/p>\n \u00a0<\/p>\n #TC<\/a>1014 #Mastery<\/a>09<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" Basic types and their use in Python<\/span><\/strong><\/p>\n Number data types store numeric values. Number objects are created when you assign a value to them. For example:<\/p>\n var1 <\/span>=<\/span> 1<\/span><\/p>\n var2 <\/span>=<\/span> 10<\/span><\/p>\n var3 = var1 + var2<\/span><\/p>\n print(var3)<\/span><\/p>\n Run code -> 11<\/span><\/p>\n Strings in Python are identified as a contiguous set of characters represented in the quotation marks.<\/span><\/p>\n str <\/span>=<\/span> ‘Hello World!’<\/span><\/p>\n print(str)<\/span><\/p>\n Run code-> Hello World!<\/span><\/p>\n Lists are the most versatile of Python’s compound data types. A list contains items separated by commas and enclosed within square brackets ([]). <\/span>The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1.<\/span><\/p>\n list <\/span>=<\/span> [<\/span> ‘abcd’<\/span>,<\/span> 786<\/span> ,<\/span> 2.23<\/span>,<\/span> ‘john’<\/span>,<\/span> 70.2<\/span> ]<\/span><\/p>\n print(list)<\/span><\/p>\n print(list[0])<\/span><\/p>\n Run code:<\/span><\/p>\n [‘abcd’, 786, 2.23, ‘john’, 70.200000000000003]<\/p>\n abcd<\/p>\n A tuple consists of a number of values separated by commas. <\/span>The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as <\/span>read-only<\/strong> lists.<\/span><\/p>\n tuple <\/span>=<\/span> (<\/span> ‘abcd’<\/span>,<\/span> 786<\/span> ,<\/span> 2.23<\/span>,<\/span> ‘john’<\/span>,<\/span> 70.2<\/span> )<\/span><\/p>\n print(tuple)<\/span><\/p>\n print(tuple[0])<\/span><\/p>\n Run code:<\/span><\/p>\n (‘abcd’, 786, 2.23, ‘john’, 70.200000000000003)<\/p>\n abcd<\/p>\n They work like associative arrays or hashes found in Perl and consist of key-value pairs. <\/span>Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]).<\/span><\/p>\n dict <\/span>=<\/span> {}<\/span><\/p>\n dict<\/span>[<\/span>‘one’<\/span>]<\/span> =<\/span> “This is one”<\/span><\/p>\n dict<\/span>[<\/span>2<\/span>]<\/span> =<\/span> “This is two”<\/span><\/p>\n print<\/span> dict<\/span>[<\/span>‘one’<\/span>]<\/span><\/p>\n print<\/span> dict<\/span>[<\/span>2<\/span>]<\/span><\/p>\n Run code:<\/span><\/p>\n This is one<\/p>\n This is two<\/p>\n <\/p>\n\n
\n
\n
\n
\n
\n
\n
\n
\n
\n