# Dictionary >>> my_dict = {‘name’: ‘Kenneth’, ‘job’: ‘Teacher’} # Keys >>> my_dict[‘job’] ‘Teacher’ # Dictionaries as keys >>> name_dict […]
Read Morea_list.append( [4, 5] ) my_list = list( range(10) ) my_list + [10, 11, 12] our_list.extend( range(5,11) ) alpha.insert(1,’b’) new_list = […]
Read MoreUsing stylesheets, images and scripts will improve the appearance and experience of your app greatly. Place these files inside a folder […]
Read MoreInstead of repeating your HTML code for each template file you can use template inheritance, where templates can inherit from each […]
Read MoreApp Inline HTML As you saw, Views can print variables. But it also can print HTML code on the web […]
Read MoreQuery Strings Sending arguments and variables to URLs is important. Users can do that using Query Strings which are the […]
Read MoreIntro Flask is a great Python microframework that can make building web sites and applications much faster. It offers some […]
Read Moremonster.py import random from combat import Combat COLORS = [‘yellow’, ‘red’, ‘blue’, ‘green’] class Monster(Combat): min_hit_points = 1 max_hit_points = […]
Read MoreYou can override an inherited method in a class by simply re-defining it in the subclass. #[combat.py]: import random class […]
Read More#[character.py] class Character: experience = 0 hit_points = 10 def get_weapon(self): weapon_choice = input(“Weapon ([S]word, [A]xe, [B]ow: “).lower() if weapon_choice […]
Read MoreIt is a special method that is called whenever something is converted into a string. >>> from monster import Dragon >>> […]
Read MoreAdd New Attributes Set foreign values of corresponding keys as new attributes in the sent self instance, with the setattr( […]
Read MoreRandom Choice >>> my_list = list(range(50)) >>> my_list [0,1,2,3,4, … , 49] >>> import random >>> random.choice(my_list) 15 >>> random.choice(my_list) […]
Read Moreenumerate( iterable ) Printing List via for-loop >>> my_alphabet_list = list(‘abcdefghijklmnopqrstuvwxyz’) >>> count = 0 >>> for letter in my_alphabet_list: … […]
Read More