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 |