{"id":112668,"date":"2022-05-17T11:57:07","date_gmt":"2022-05-17T11:57:07","guid":{"rendered":"https:\/\/codeinstitute.net\/global\/?p=112668"},"modified":"2022-05-17T11:57:07","modified_gmt":"2022-05-17T11:57:07","slug":"python-cheat-sheet","status":"publish","type":"post","link":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/","title":{"rendered":"Python Cheat Sheet"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Python is one of the most popular programming languages. It currently takes first place both in the Tiobe index and the PYPL index and has been named Language of the Year in 2007, 2010, 2018, 2020, and 2021. This popularity stems both from Python\u2019s versatility and ease of use. Python <a href=\"https:\/\/codeinstitute.net\/global\/blog\/what-is-python-used-for\/\" target=\"_blank\" rel=\"noreferrer noopener\">can be used for<\/a> Web and Internet Development, Data Analysis and Machine Learning, Scripting, Software Testing, and Desktop GUIs (graphical user interfaces). Python uses a simple syntax and is very beginner-friendly. It is therefore a great choice for entry-level coders. The Python cheat sheet will introduce you to some important Python concepts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python uses an elegant syntax and uncluttered layout. Combined with frequently used English keywords like \u2018continue\u2019, \u2018return\u2019, and \u2018import\u2019, this makes Python a highly readable language.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Indentation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">One of the main characteristics of Python is indentation. While other programming languages, like <a href=\"https:\/\/codeinstitute.net\/global\/blog\/what-is-java\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java<\/a> and <a href=\"https:\/\/codeinstitute.net\/global\/blog\/what-is-javascript-and-why-should-i-learn-it\/\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript<\/a>, use braces to separate blocks of code, Python code blocks are identified by different levels of line indentation. Here is a code example using multiple levels of indentation:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>def printer_errors(s):\n    errors = 0 # first level of indentation\n    for letter in s:\n        if letter &gt; &#39;m&#39;: # second level of indentation\n            errors += 1 # third level of indentation\n    return f&#39;{errors}\/{len(s)}&#39; # first level of indentation<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Writing the code without or with wrong indentation will lead to an error, and the code won\u2019t be executed. It is best practice to use 4 spaces per level of indentation. It is possible to use either spaces or the Tabulator key for indentation, but you should stick to using either spaces or tabs.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Comments<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The hash sign from the above example is used for comments. Everything after the hash sign will be ignored by the Python interpreter and is used to add comments either for yourself or other people reading the code. Comments can be added above a line of code or next to a line of code, like in the above example. For long comments that span multiple lines, the hash sign can be added to the start of each new line, or the comment can be placed inside triple-quotes, like in the instruction below:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># The function returns the number of errors in a given control string.\n# Letters from a to m are used to differentiate between colours.\n# All other letters indicate an error.\n# Write a function that returns the number of errors and the length of the control string.\n\n&#39;&#39;&#39;\nExamples:\ns = &#39;adgbfbchaifjm&#39;\nprinter_errors(s) # Output: &#39;0\/14&#39;\n&#39;&#39;&#39;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Quotation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is possible to use single (&#8216;), double (&#8220;), and triple (&#8221;&#8217; or &#8220;&#8221;&#8221;) quotes in Python. It is, however, important and necessary to use the same kind of quote at the start and end of a string. If the string itself contains quotes, they must not match the outer quotes. Like with comments, triple quotes are used for strings that span multiple lines. See the examples below:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>name = &#39;Thomas&#39;\ncolour = &quot;blue&quot;\nsentence = &quot;It&#39;s a pleasure to meet you!&quot; # note the single quote \nparagraph = &#39;&#39;&#39;One Ring to rule them all, One Ring to find them, One Ring to bring them all, and in the darkness bind them.&#39;&#39;&#39;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Keywords<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A Python identifier is a name used to identify a variable, function, class or module. It is best practice to use descriptive names, like &#8216;first_name&#8217; or &#8216;calculate_stardate(year)&#8217;, to make the code easier to understand. Some identifiers are reserved by the Python language and cannot be used as ordinary identifiers. They are listed in the table below.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>False<\/td><td>await<\/td><td>else<\/td><td>import<\/td><td>pass<\/td><\/tr><tr><td>None<\/td><td>break<\/td><td>except<\/td><td>in<\/td><td>raise<\/td><\/tr><tr><td>True<\/td><td>class<\/td><td>finally<\/td><td>is<\/td><td>return<\/td><\/tr><tr><td>and<\/td><td>continue<\/td><td>for<\/td><td>lambda<\/td><td>try<\/td><\/tr><tr><td>as<\/td><td>def<\/td><td>from<\/td><td>nonlocal<\/td><td>while<\/td><\/tr><tr><td>assert<\/td><td>del<\/td><td>global<\/td><td>not<\/td><td>with<\/td><\/tr><tr><td>async<\/td><td>elif<\/td><td>if<\/td><td>or<\/td><td>yield<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Python primitive data structures<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are four types of primitive data structures in Python. They contain pure values of data and are essential for data manipulation.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">String<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To display sequences of character data in Python, the string type (abbreviated as str) is used. In most cases, strings will be words, but it is possible to put licence plates, passwords, symbols, or even numbers into an str variable.\u00a0 A string can be empty. The only limitation regarding length is the available computer memory. <a href=\"https:\/\/codeinstitute.net\/global\/blog\/a-guide-to-strings-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Strings<\/a> can be used with single, double, and triple quotes like mentioned above in the Quotation section.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">String methods<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Strings in Python are immutable, which means they cannot be changed. However, it is possible to return a modified copy of a string by using string methods. To keep the modified string, it must be assigned to a new variable! Below, the most common string methods are listed with a short explanation.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>text = &#39;Hello, World!&#39; # assign &#39;Hello, World!&#39; to the variable text\nvulcan_greeting = &#39; Live long and prosper! &#39; # note the spaces at the start and end of the string\nlist_of_strings = [&#39;Nice&#39;, &#39;to&#39;, &#39;meet&#39;, &#39;you&#39;]\n\n&#39; &#39;.join(list_of_strings) # join all the strings by the delimiter (in this case an empty space). Output: &#39;Nice to meet you&#39;\ntext.capitalize() # convert the first character to upper case. Output: &#39;Hello, world!&#39;\ntext.count(&#39;o&#39;) # return the number of occurrences of the specified substring. Output: 2\ntext.endswith(&#39;o&#39;) # return True if the string ends with the specified substring. Output: False\ntext.find(&#39;o&#39;) # return the lowest index of the specified substring. Output: 4 (the index starts with 0)\ntext.islower() # return True if all cased characters are lowercase and the string contains at least one character. Output: False\ntext.istitle() # return True if the string is titlecased and contains at least one character. Output: True\ntext.isupper() # return True if the string is in uppercase and contains at least one character. Output: False\nvulcan_greeting.lstrip() # remove the left whitespace. Output: &#39;Live long and prosper!&#39;\ntext.lower() # convert the string into lower case. Output: &#39;hello, world!&#39;\ntext.replace(&#39;World&#39;, &#39;Universe&#39;) # return the string with all occurrences of the first substring replaced by the second substring. Output: &#39;Hello, Universe&#39;\nvulcan_greeting.rsplit() # remove the right whitespace. Output &#39; Live long and prosper!&#39;\ntext.split() # split the string into separate words and return a list. Output: [&#39;Hello,&#39;, &#39;World&#39;]\nvulcan_greeting.strip() # remove whitespace from both ends of the string. Output: &#39;Live long and prosper!&#39;\ntext.startswith(&#39;o&#39;) # return True if the string starts with the specified substring. Output: False\ntext.swapcase() # swaps lower case to upper case and vice versa. Output: &#39;hELLO, wORLD&#39;\nvulcan_greeting.title() # convert the first letter of each word to upper case. Output: &#39;Live Long And Prosper!&#39;\ntext.upper() # convert the string into upper case. Output: &#39;HELLO, WORLD!&#39;<\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">String concatenation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">It is possible to combine (or concatenate) multiple strings by using the + operator. When alpha-numeric strings are concatenated, the result might at first be surprising. Instead of adding them up, they are just written next to each other:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>greeting = &#39;Hello!&#39;\nquestion = &#39;Do you want some coffee?&#39;\ngreeting + question # Output:&#39;Hello! Do you want some coffee?&#39;\nx = &#39;7&#39;\ny = &#39;5&#39;\nx + y # Output: 75<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">It is also possible to repeat strings by using the * operator:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>greeting * 3 # Output: Hello!Hello!Hello!<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Numeric: Integer and Float<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integers are whole numbers from negative infinity to infinity. There are no limits to the length of an integer value, except the amount of available memory. All decimal digits without a prefix will be treated as decimal numbers. To use another base, a prefix must be added to the integer value. The prefix for binary numbers using the base 2 is 0b or 0B, to use octal numbers with the base 8 add 0o or 0O, and for hexadecimal numbers with the base 16 add 0x or 0X.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Float (for floating point number) values end with a decimal figure, e.g. 2.75. The difference between integers and floats is very important for division. Using the division operator \/ always results in a float:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>6 \/ 3 # Output: 2.0\n6 \/ 3.0 # Output: 2.0\n6.0 \/ 3 # Output: 2.0\n6.0 \/ 3.0 # Output: 2.0<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Using integer division with \/\/ results in an integer, if both dividend and divisor are integers, and in a float in all other cases. For the numbers from the above example, not much will change. However, if the result of an integer division is not a whole number, it will always be rounded towards the lesser integer value. Integer division is therefore also called floor division.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>6 \/\/ 4 # Output: 1\n6.0 \/\/ 4 # Output: 1.0<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Boolean<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Objects of Boolean type can have one of two values: True or False. Booleans can be used both in conditional and comparison expressions.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># Comparison expressions\nx = 5\ny = 10\n\nx &lt; y # Output: True\nx &gt; y # Output: False\nx + 7 &gt; y # Output: True\nX &lt;= y # Output: True\nX &gt;= y # Output: False\nx == y # Output: False\nx != y # Output: True\n\n# Conditional expressions\ntemperature_in_degrees_celsius = 20\nsunny = temperature_in_degrees_celsius &gt;= 20 # evaluates to True\ncold = temperature_in_degrees_celsius &lt;= 10 # evaluates to False\n\nif sunny: \n    print(&#39;Wear a t-shirt&#39;)\nelif cold:\n    print(&#39;Wear a pullover and a jacket&#39;)\nelse:\n    print(&#39;More information needed to make a suggestion!&#39;)\n\n# Output: &#39;Wear a t-shirt&#39;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Python Built-in non-primitive data structures<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python provides several built-in non-primitive data structures to store and organize a collection of values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dictionaries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a dictionary, keys are mapped with values. Each combination of a key and a value is called a key-value pair or an item. While the values in a dictionary can be of any type and different values can be of different types, the keys must be <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-hashable\">hashable<\/a>. Most often, strings and numbers are used as dictionary keys. The keys are immutable and unique. The dictionaries themselves are mutable. It is possible to add, delete, or change key-value elements.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a dictionary:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># Create an empty dictionary eng_ger \neng_ger = {}\n\n# Typecast an empty dictionary ger_eng\nger_eng = dict()\n\n# Create a dictionary from two iterables\nweekdays = [&#39;Monday&#39;, &#39;Tuesday&#39;, &#39;Wednesday&#39;, &#39;Thursday&#39;, &#39;Friday&#39;, &#39;Saturday&#39;, &#39;Sunday&#39;]\nweekday_numbers = [1, 2, 3, 4, 5, 6, 7]\n\n# zip both lists\nweekdays_with_numbers = dict(zip(weekdays, weekday_numbers))\nprint(weekdays_with_numbers) # Output: {&#39;Monday&#39;: 1, &#39;Tuesday&#39;: 2, &#39;Wednesday&#39;: 3, &#39;Thursday&#39;: 4, &#39;Friday&#39;: 5, &#39;Saturday&#39;: 6, &#39;Sunday&#39;: 7}<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Adding, replacing, and deleting items:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># Add multiple key-value pairs to an empty dictionary\neng_ger = {&#39;car&#39;: &#39;Automobil&#39;, &#39;house&#39;: &#39;Haus&#39;, &#39;cat&#39;: &#39;Katze&#39;}\nprint(eng_ger) # Output: {&#39;car&#39;: &#39;Automobil&#39;, &#39;house&#39;: &#39;Haus&#39;, &#39;cat&#39;: &#39;Katze&#39;}\n\n# Add a key-value-pair to an existing, non-empty dictionary\neng_ger[&#39;dog&#39;] = &#39;Hund&#39;\nprint(eng_ger) # output: {&#39;car&#39;: &#39;Automobil&#39;, &#39;house&#39;: &#39;Haus&#39;, &#39;cat&#39;: &#39;Katze&#39;, &#39;dog&#39;: &#39;Hund&#39;}\n# Modify the value of an existing key\neng_ger[&#39;car&#39;] = &#39;Auto&#39;\nprint(eng_ger[&#39;car&#39;] # Output: Auto\n\n# Remove key-value pairs from a dictionary\ndel eng_ger[&#39;car&#39;]\nprint(eng_ger) # output: {&#39;house&#39;: &#39;Haus&#39;, &#39;cat&#39;: &#39;Katze&#39;, &#39;dog&#39;: &#39;Hund&#39;}  \n\n# Remove all items from a dictionary\neng_ger.clear()\nprint(eng_ger) # Output: {}<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Check whether a key or a value is contained in a dictionary:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># Check if a key is contained in a dictionary with the in keyword\nprint(&#39;mouse&#39; in eng_ger) # Output: False\n\n# Check if something appears as a value in a dictionary\nvalues_in_dict = list(eng_ger.values()) # convert into list\nprint(&#39;Katze&#39; in values_in_dict) # Output: True<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Iterate over keys, values, and key-value pairs in dictionaries:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>villains = {&#39;Star Trek&#39;: &#39;The Borg&#39;, &#39;Star Wars&#39;: &#39;The Emperor&#39;, &#39;Harry Potter&#39;: &#39;Lord Voldemort&#39;, &#39;Lord of the Rings&#39;: &#39;Sauron&#39;}\n\n# iterate over the keys short version\nfor franchise in villains:\n    print(franchise)\n\n# Output:\nStar Trek\nStar Wars\nHarry Potter\nThe Lord of the Rings\n# iterate over the keys long version\nFor franchise in villains.keys():\n    print(franchise) # Output: same as above\n\n# iterate over the values\nfor villain in villains.values(): # the values() function must be called\n    print(villain)\n\n# Output:\nThe Borg\nThe Emperor\nLord Voldemort\nSauron\n\n# iterate over the key-value pairs\nfor key, value in villains.items():\n    print(f&#39;Key: {key}, Value: {value}&#39;)\n\n# Output:\nKey: Star Trek, Value: The Borg\nKey: Star Wars, Value: the Emperor\nKey: Harry Potter, Value: Lord Voldemort\nKey: Lord of the Rings, Value: Sauron<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Get the number of key-value pairs in a dictionary:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># Get the number of key-value pairs in a dictionary\nprint(len(en_ger) # Output: 3<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Merge multiple dictionaries into one dictionary:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>villains = {&#39;Star Trek&#39;: &#39;The Borg&#39;, &#39;Star Wars&#39;: &#39;The Emperor&#39;, &#39;Harry Potter&#39;: &#39;Lord Voldemort&#39;, &#39;Lord of the Rings&#39;: &#39;Sauron&#39;}\nmore_villains = {&#39;Star Trek TOS&#39;: &#39;Khan&#39;, &#39;Fantastic Beasts&#39;: &#39;Grindelwald&#39;, &#39;Star Wars&#39;: &#39;Darth Sidious&#39;}\n\n# In case of overlapping keys between the dictionaries, the newest value will be assigned to the key\n\n# merge dictionaries with the update() function\nvillains.update(more_villains) # the villains dictionary is updated\nprint(villains)\n# Output:\n{&#39;Star Trek&#39;: &#39;The Borg&#39;, &#39;Star Wars&#39;: &#39;Darth Sidious&#39;, &#39;Harry Potter&#39;: &#39;Lord Voldemort&#39;, &#39;Lord of the Rings&#39;: &#39;Sauron&#39;, &#39;Star Trek TOS&#39;: &#39;Khan&#39;, &#39;Fantastic Beasts&#39;: &#39;Grindelwald&#39;}\n\n# merge dictionaries with unpacking\ncombined_villains = {**villains, **more_villains} # a new dictionary is created and contains all values from the villains + more_villains dictionaries\nprint(combined_villains) # Output: same as above\n\n# merge dictionaries with the dict() constructor\nvillains_combined = dict(villains, **more_villains) # the new dictionary takes the villains dictionary and combines it with the unpacked items of the more_villains dictionary\nprint(villains_combined) # Output: same as in the first example<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Lists<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Lists can contain zero or more items of different types. Like dictionaries, lists are mutable. Unlike dictionaries, the items in a list are indexed by their position, starting at 0. Lists can be sorted, reversed, sliced, and concatenated.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># create an empty list\nfriends = []\npets = list()\n\n# create a list with some items\nfavourite_colours = [&#39;blue&#39;, &#39;black&#39;, &#39;orange&#39;]<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Add and remove items:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># add an item at the end of a list\nfavourite_colours.append(&#39;green&#39;)\nprint(favourite_colours)\n# Output: [&#39;blue&#39;, &#39;black&#39;, &#39;orange&#39;, &#39;green&#39;]\n\n# insert an item at a given position\nfavourite_colours.insert(1, &#39;yellow&#39;)\nprint(favourite_colours)\n# Output: [&#39;blue&#39;, &#39;yellow&#39;, &#39;black&#39;, &#39;orange&#39;, &#39;green&#39;]\n\n# extend a list by appending another list\nmore_colours = [&#39;red&#39;, &#39;grey&#39;, &#39;silver&#39;, &#39;purple&#39;]\nfavourite_colours.extend(more_colours)\nprint(favourite_colours)\n# Output: [&#39;blue&#39;, &#39;yellow&#39;, &#39;black&#39;, &#39;orange&#39;, &#39;green&#39;, &#39;red&#39;, &#39;grey&#39;, &#39;silver&#39;, &#39;purple&#39;]\n\n# remove an item value from a list\nfavourite_colours.remove(&#39;yellow&#39;)\nprint(favourite_colours)\n# Output: [&#39;blue&#39;, &#39;black&#39;, &#39;orange&#39;, &#39;green&#39;, red&#39;, &#39;grey&#39;, &#39;silver&#39;, &#39;purple&#39;]\n\n# remove the last item from a list\nfavourite_colours.pop()\nprint(favourite_colours)\n# Output: [&#39;blue&#39;, &#39;black&#39;, &#39;orange&#39;, &#39;green&#39;, red&#39;, &#39;grey&#39;, &#39;silver&#39;]\n\n# remove an item at a given position from a list\nfavourite_colours.pop(3)\nprint(favourite_colours)\n# Output: [&#39;blue&#39;, &#39;black&#39;, &#39;orange&#39;, &#39;red&#39;, &#39;grey&#39;, &#39;silver&#39;]\n\n# remove all items from a list\nmore_colours.clear()\nprint(more_colours)\n# Output: []<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sort and reverse:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># sort a list alphabetically\nfavourite_colours.sort()\nprint(favourite_colours)\n# Output: [&#39;black&#39;, &#39;blue&#39;, &#39;grey&#39;, &#39;orange&#39;, &#39;red&#39;, &#39;silver&#39;]\n\n# reverse a list\nfavourite_colours.reverse()\nprint(favourite_colours()\n# Output: [&#39;silver&#39;, &#39;red&#39;, &#39;orange&#39;, &#39;grey&#39;, &#39;blue&#39;, &#39;black&#39;]<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Count:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># return the number of items in a list\nprint(len(favourite_colours)\n# Output: 6\n\n# return the number of occurrences of a specified value\nprint(favourite_colours.count(&#39;grey&#39;))\n# Output: 1<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tuples<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Like lists, the values in a tuple are indexed by integers, and tuples can contain elements of different types. The most important difference is that tuples are immutable. This means there are fewer functions available for tuples than for lists, because tuples can\u2019t be modified. Why should tuples be used if they seem to be a light version of a list?&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Tuples use less space than lists<\/li><li>They can\u2019t be changed by mistake<\/li><li>They can be used as dictionary keys. This allows us to get a sorted version of a dictionary<\/li><li>They are comparable<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create tuples:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># Enclose tuples in parentheses to make them quickly identifiable\nvowels = (&#39;a&#39;, &#39;e&#39;, &#39;i&#39;, &#39;o&#39;, &#39;u&#39;)\n\n# When creating a tuple with a single element, a final comma has to be included to prevent it from being treated as a string\nnot_a_string = (&#39;a&#39;,)<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Sets<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sets can consist of zero or more elements and can contain elements of different types. Sets are mutable and unordered collections that don\u2019t allow duplicates. They are mostly used to test whether a value exists in the set, and to compute the union, intersection, difference, and symmetric difference of two sets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create sets:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>vowels = {&#39;a&#39;, &#39;e&#39;, &#39;i&#39;, &#39;o&#39;, &#39;u&#39;}\n\n# use the set() constructor for empty sets to avoid creating an empty dictionary\nempty_set = set()<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set methods:<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># test whether a value exists in a set\n&#39;y&#39; in vowels\nFalse\n\n# add a single item\nvowels.add(&#39;y&#39;)\nprint(vowels)\n# Output: {&#39;u&#39;, &#39;y&#39;, &#39;o&#39;, &#39;e&#39;, &#39;i&#39;, &#39;a&#39;}\n\n# add multiple items as a list\nvowels.update(&#39;x&#39;, &#39;z&#39;, &#39;k&#39;)\nprint(vowels)\n# Output: {&#39;z&#39;, &#39;e&#39;, &#39;y&#39; &#39;k&#39;, &#39;a&#39;, &#39;x&#39;, &#39;u&#39;, &#39;i&#39;, &#39;o&#39;}\n\n# remove a single item\nvowels.discard(&#39;y&#39;)\nprint(vowels)\n# Output: {&#39;k&#39;,&#39;z&#39;, &#39;e&#39;, &#39;a&#39;, &#39;u&#39;, &#39;i&#39;, &#39;x&#39;, &#39;o&#39;}\nvowels.discard(&#39;x&#39;)\nvowels.discard(&#39;z&#39;)\nvowels.discard(&#39;k&#39;)\n\nname = set(&#39;oscar&#39;)\n# check for values in both sets\nprint(name.intersection(vowels)\n# Output: {&#39;o&#39;, &#39;a&#39;}\n\n# check for values that are in either set or both\nprint(name.union(vowels)\n# Output: {&#39;o&#39;, &#39;r&#39;, &#39;y&#39;, &#39;c&#39;, &#39;a&#39;, &#39;i&#39;, &#39;e&#39;, &#39;u&#39;, &#39;s&#39;}\n\n# check for values that are in the first set but not the second\nprint(name.difference(vowels)\n# Output: {&#39;r&#39;, &#39;s&#39;, &#39;c&#39;}\n\n# check for values that are in one of the sets, but not both of them\nprint(name.symmetric_difference(vowels)\n# Output: {&#39;r&#39;, &#39;y&#39;, &#39;c&#39;, &#39;e&#39;, &#39;u&#39;, &#39;s&#39;, &#39;i&#39;}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Python Libraries<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Python <a href=\"https:\/\/codeinstitute.net\/global\/blog\/what-are-libraries-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">library<\/a> is a reusable collection of code or modules (a file with Python code in it) that can be used in programs or projects. The advantage lies in not having to write the code again and again. It is possible to simply import either separate functions or complete modules into our programs to make them available.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code># import only the needed method\nFrom math import sqrt\n\n# import the complete module with all methods\nimport math<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Another advantage is not to reinvent the wheel every time, and instead to use already existing and proven code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Python standard library<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Python core distribution contains the Python standard library with more than 200 modules. These modules allow access to basic system functionality and core modules. Some of the most important modules and some of their included functions are listed below. The built-in function dir(&lt;module&gt;) returns all module functions in a list. Use help(&lt;module&gt;) to see a manual page from the module\u2019s docstrings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The os module<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The functions in the os module allow interactions with the operating system.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>import os\n\nos.chdir(&#39;&lt;path of directory&gt;&#39;) # change current working directory\nos.getcwd() # return the current working directory\nos.listdir() # list the files and directories in the current working directory<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The math module<\/strong> allows access to the mathematical functions.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>import math\n\nx = 3.75\n\nmath.ceil(x) # return the smallest integer greater than or equal to x. Output = 4\nmath.floor(x) # return the largest integer less than or equal to x. Output = 3\nmath.sin(x) # return the sine of x radians. Output = -0.5715613187423437\nmath.sqrt(x) # return the square root of x. Output = 1.9364916731037085<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The random module<\/strong> is used for random selections.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-python\" data-lang=\"Python\"><code>import random\n\nrandom.random() # returns a random float\nrandom.randrange(12)) # returns a random integer in the range from 0 - 12\nrandom.sample(range(100), 5)) # returns a list of 5 integers in the range from 0 - 100<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Other modules provide tools for string pattern matching (import re), the calculation of statistical properties (import statistics), sending mail (import smtplib), manipulating dates and times (import datetime), and writing tests for functions or units (import doctest, import unittest).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Additionally, there are over 137,000 Python libraries available. The <a href=\"https:\/\/pypi.org\/\">Python Package Index<\/a> (PyPi) is a repository where users can find, install, and distribute Python software.<\/p>\n\n\n\n<p class=\"has-text-align-right wp-block-paragraph\"><em><em>Scott B\u00f6ning, Code Institute Graduate<\/em><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Experience Software Development<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t let the information above phase you. If you\u2019ve landed on this page, it\u2019s a good start. If you\u2019re new to software development and want to learn some basic programming, register for our free <a href=\"https:\/\/codeinstitute.net\/global\/5-day-coding-challenge\/\" target=\"_blank\" rel=\"noreferrer noopener\">5 Day Coding Challenge<\/a> through the form below.\u00a0If you&#8217;ve already done the coding challenge, we do teach Python as part of our Full Stack Software Development Programme. Click <a href=\"https:\/\/codeinstitute.net\/global\/full-stack-software-development-diploma\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> to find out more. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python is one of the most popular programming languages. It currently takes first place both in the Tiobe index and the PYPL index and has been named Language of the Year in 2007, 2010, 2018, 2020, and 2021. This popularity stems both from Python\u2019s versatility and ease of use. Python can be used for Web [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":112697,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9,27],"tags":[416,79,109],"class_list":["post-112668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-python","tag-learn-to-code","tag-python","tag-technology"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Cheat Sheet | Data Structures, Syntax &amp; More - Code Institute Global<\/title>\n<meta name=\"description\" content=\"Python is a great choice for entry-level coders. This Python Cheat Sheet will introduce you to some important Python concepts.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Cheat Sheet | Data Structures, Syntax &amp; More - Code Institute Global\" \/>\n<meta property=\"og:description\" content=\"Python is a great choice for entry-level coders. This Python Cheat Sheet will introduce you to some important Python concepts.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Institute Global\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-17T11:57:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet.png.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Guest Author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet.png.webp\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Guest Author\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/\"},\"author\":{\"name\":\"Guest Author\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#\\\/schema\\\/person\\\/59a8fa654948023b958f9dba01fb87e7\"},\"headline\":\"Python Cheat Sheet\",\"datePublished\":\"2022-05-17T11:57:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/\"},\"wordCount\":1574,\"publisher\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/d3m1rm8xuevz4q.cloudfront.net\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/Python-Cheat-Sheet-2.png.webp\",\"keywords\":[\"Learn to Code\",\"Python\",\"Technology\"],\"articleSection\":[\"Coding\",\"Python\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/\",\"url\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/\",\"name\":\"Python Cheat Sheet | Data Structures, Syntax & More - Code Institute Global\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/d3m1rm8xuevz4q.cloudfront.net\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/Python-Cheat-Sheet-2.png.webp\",\"datePublished\":\"2022-05-17T11:57:07+00:00\",\"description\":\"Python is a great choice for entry-level coders. This Python Cheat Sheet will introduce you to some important Python concepts.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#primaryimage\",\"url\":\"https:\\\/\\\/d3m1rm8xuevz4q.cloudfront.net\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/Python-Cheat-Sheet-2.png.webp\",\"contentUrl\":\"https:\\\/\\\/d3m1rm8xuevz4q.cloudfront.net\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/Python-Cheat-Sheet-2.png.webp\",\"width\":1500,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/python-cheat-sheet\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Cheat Sheet\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#website\",\"url\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/\",\"name\":\"Code Institute Global\",\"description\":\"A New Career in Tech\",\"publisher\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#organization\",\"name\":\"Code Institute Global\",\"url\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/d3m1rm8xuevz4q.cloudfront.net\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Web_grey_logo-1.png.webp\",\"contentUrl\":\"https:\\\/\\\/d3m1rm8xuevz4q.cloudfront.net\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Web_grey_logo-1.png.webp\",\"width\":251,\"height\":105,\"caption\":\"Code Institute Global\"},\"image\":{\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/#\\\/schema\\\/person\\\/59a8fa654948023b958f9dba01fb87e7\",\"name\":\"Guest Author\",\"description\":\"From time to time, students, graduates, and colleagues of Code Institute contribute to our blogs and articles. Here's where you will find them.\",\"url\":\"https:\\\/\\\/codeinstitute.net\\\/global\\\/blog\\\/author\\\/guest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Cheat Sheet | Data Structures, Syntax & More - Code Institute Global","description":"Python is a great choice for entry-level coders. This Python Cheat Sheet will introduce you to some important Python concepts.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/","og_locale":"en_US","og_type":"article","og_title":"Python Cheat Sheet | Data Structures, Syntax & More - Code Institute Global","og_description":"Python is a great choice for entry-level coders. This Python Cheat Sheet will introduce you to some important Python concepts.","og_url":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/","og_site_name":"Code Institute Global","article_published_time":"2022-05-17T11:57:07+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet.png.webp","type":"image\/webp"}],"author":"Guest Author","twitter_card":"summary_large_image","twitter_image":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet.png.webp","twitter_misc":{"Written by":"Guest Author","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#article","isPartOf":{"@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/"},"author":{"name":"Guest Author","@id":"https:\/\/codeinstitute.net\/global\/#\/schema\/person\/59a8fa654948023b958f9dba01fb87e7"},"headline":"Python Cheat Sheet","datePublished":"2022-05-17T11:57:07+00:00","mainEntityOfPage":{"@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/"},"wordCount":1574,"publisher":{"@id":"https:\/\/codeinstitute.net\/global\/#organization"},"image":{"@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#primaryimage"},"thumbnailUrl":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet-2.png.webp","keywords":["Learn to Code","Python","Technology"],"articleSection":["Coding","Python"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/","url":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/","name":"Python Cheat Sheet | Data Structures, Syntax & More - Code Institute Global","isPartOf":{"@id":"https:\/\/codeinstitute.net\/global\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#primaryimage"},"image":{"@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#primaryimage"},"thumbnailUrl":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet-2.png.webp","datePublished":"2022-05-17T11:57:07+00:00","description":"Python is a great choice for entry-level coders. This Python Cheat Sheet will introduce you to some important Python concepts.","breadcrumb":{"@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#primaryimage","url":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet-2.png.webp","contentUrl":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/05\/Python-Cheat-Sheet-2.png.webp","width":1500,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/codeinstitute.net\/global\/blog\/python-cheat-sheet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codeinstitute.net\/global\/"},{"@type":"ListItem","position":2,"name":"Python Cheat Sheet"}]},{"@type":"WebSite","@id":"https:\/\/codeinstitute.net\/global\/#website","url":"https:\/\/codeinstitute.net\/global\/","name":"Code Institute Global","description":"A New Career in Tech","publisher":{"@id":"https:\/\/codeinstitute.net\/global\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codeinstitute.net\/global\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codeinstitute.net\/global\/#organization","name":"Code Institute Global","url":"https:\/\/codeinstitute.net\/global\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codeinstitute.net\/global\/#\/schema\/logo\/image\/","url":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/02\/Web_grey_logo-1.png.webp","contentUrl":"https:\/\/d3m1rm8xuevz4q.cloudfront.net\/wp-content\/uploads\/2022\/02\/Web_grey_logo-1.png.webp","width":251,"height":105,"caption":"Code Institute Global"},"image":{"@id":"https:\/\/codeinstitute.net\/global\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/codeinstitute.net\/global\/#\/schema\/person\/59a8fa654948023b958f9dba01fb87e7","name":"Guest Author","description":"From time to time, students, graduates, and colleagues of Code Institute contribute to our blogs and articles. Here's where you will find them.","url":"https:\/\/codeinstitute.net\/global\/blog\/author\/guest\/"}]}},"_links":{"self":[{"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/posts\/112668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/comments?post=112668"}],"version-history":[{"count":0,"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/posts\/112668\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/media\/112697"}],"wp:attachment":[{"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/media?parent=112668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/categories?post=112668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinstitute.net\/global\/wp-json\/wp\/v2\/tags?post=112668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}