![]() ![]() Looping through a list is the same as going to the mall and working off your grocery list top to bottom: the first item to collect are apples, once you have those, you need to fetch pears, and so on. ![]() Items can be inserted halfway the list with the list.insert( i, item) command, where the i parameter is the position where you want the element to be. > "eggs" ] To remove the eggs from the list: del groceries To append an item to the end of the list: groceries. New items can be added to it, or old items deleted from it, just like you can add stuff to buy to a grocery sticky-note, or scratch out things. Adding items to the listĭata in a list can change over the course of time. That's why in the above example the fourth element is replaced. > ĭon't forget: items in a list start with index zero. > apples groceries = "banana" print groceries You can reference items in a list directly, by adding the index of the item you want to the variable name, between square brackets: print groceries The len( list) command returns the number of items in a list. groceries = print len (groceries )Ī list can contain any kind of data: strings, numbers, and even lists. The list is assigned to a variable named groceries, but we know that variables can have any name we like, so it could be named g or stufftodo as well for that matter. Each item in the list is a piece of text (a string), therefore they are embedded in quotes. The list is defined between square brackets. So, what does the code look like? Below is the grocery list defined in NodeBox. The first element in a list has index zero, the second element in a list has index one. The main difference is that in real life, we usually start counting from one, while lists in programming start from zero. Lists are essential when your scripts increase in complexity: they are a way to group bits and pieces of information that belong together, for example: all the words to draw on screen, all the possible colors from which the script can choose, all the fonts from which the script can choose.Ī list in NodeBox is no different from a list in real life: it can hold a summary of stuff to do, groceries to buy, a sheet of names and adressess. # Drag this node around when the mouse is moved.ĭx = - 250 # Undo translate().Variables can hold entire lists of data. # When the mouse is pressed, remember on which node. # With weighted=0.0-1.0, indicates nodes whose centrality > the given threshold. # With weighted=True, Node.centrality is indicated by a shadow under high-traffic nodes. # With directed=True, edges have an arrowhead indicating the direction of the connection. G.layout.repulsion = 15 # Repulsion radius. G.layout.force = 0.01 # Strength of the attractive
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |