Each item in a dictionary is a key-value pair. Conditional tests equals x = 42 not equal x != 42 greater than x > 42 or equal to x >= 42 less than x < 42 or equal to x <= 42 Conditional test with lists ' trek' in bikes ' surly' not in bikes Assigning boolean values game_active = True can_edit = False A simple if test if age >= 18: print('You can vote!') If-elif-else statements if age < 4: ticket_price = 0 elif age < 18: ticket_price = 10 else: ticket_price = 15 Covers Python 3 and Python 2 Dictionaries store connections between pieces of information.Making a tuple dimensions = (1920, 1080) If statements are used to test for particular conditions and respond appropriately. Make a list bikes = Get the first item in a list first_bike = bikes Get the last item in a list last_bike = bikes Looping through a list for bike in bikes: print(bike) Adding items to a list bikes = bikes(' trek' ) bikes(' redline' ) bikes(' giant' ) Making numerical lists squares = for x in range(1, 11): squares(x**2) List comprehensions squares = Slicing a list finishers = first_two = finishers Copying a list copy_of_bikes = bikes Tuples are similar to lists, but the items in a tuple can' t be modified. You access items using an index, or within a loop. Hello world print('Hello world!') Hello world with a variable msg = 'Hello world!' print(msg) Concatenation (combining strings) first_name = ' albert' last_name = ' einstein' full_name = first_name + ' ' + last_name print(full_name) A list stores a series of items in a particular order. A string is a series of characters, surrounded by single or double quotes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |