This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # --> METHOD 1: The Pythonic way | |
| import copy | |
| list_copy = copy.deepcopy(whoops_list) | |
| print(list_copy is whoops_list) # Spoiler, it's False | |
| # --> METHOD 2: The 'I don't have time for this!' guy | |
| # Don't be this guy | |
| list_copy_2 = whoops_list[:] | |
| print(list_copy_2 is whoops_list) # Spoiler, it's False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # we define a list (mutable type) | |
| whoops_list = ["I", "am", "really good", "at Python"] | |
| # we equal this list to another variable | |
| i_am_really_bad_at_python_list = whoops_list | |
| # we append an item tho the SECOND list | |
| i_am_really_bad_at_python_list.append("OR AM I????") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sets are unordered lists of UNIQUE ITEMS, like dictionaries but without | |
| # values, only keys. | |
| set_numbers = {5, 3, 6, 7, 7, 7, 7} | |
| print(set_numbers) | |
| # they are useful when you need to know which items are in one set and not in the other | |
| set_numbers_2 = {1, 2, 3, 4, 5} | |
| # this will print the intersection which is another set = {3, 5} | |
| print(set_numbers_2.intersection(set_numbers)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DISCLAIMER: any coincidence with reality is pure luck, no spoilers ahead | |
| # having this dictionary of key: GoT character and value: a boolean answering if it's alive or not | |
| d_got_is_alive = {"John Snow": True, "Tyrion Lannister": True, "Ned Stark": True} | |
| # to retrieve an item, like lists but by the KEY | |
| print(d_got_is_alive["Ned Stark"]) | |
| # example with for loop | |
| # the method .keys() of a dictionary returns a list of the keys in the dictionary. WATXAUT! It might not be ordered! | |
| for key in d_got_is_alive.keys(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| list_numbers = [12, 33, 44, 55] | |
| # lists of list are also possible! You can create matrix for example | |
| jacobean_matrix = [ | |
| [3, 4, 5], | |
| [1, 0, 4], | |
| [0, 3, 1] | |
| ] | |
| # to add things to lists (remember, mutable means mutable like it can change) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| i = 0 | |
| # if you mess with the next line -> boom, infinite loop | |
| while i < 10: | |
| print(i) | |
| # if you don't include this line -> boom, infinite loop | |
| i = i + 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # here we have one boolean | |
| some_true_condition = True | |
| # if the boolean is True, it will print, if not, it won't do anything | |
| if some_true_condition == True: | |
| print("Hey this is True") | |
| if some_true_condition: # This is the same, but more Pythonic | |
| print("Hey this still is True") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Examples of immutable variables in Python | |
| # ----> Numbers | |
| integer_num = 4 | |
| float_num = 4.5 | |
| complex_num = 4j | |
| # ----> Strings | |
| string_sentence = "Hey I am immutable" | |
| string_with_simple_quotes = 'I am immutable and I am still a string' |