list_items.py
animals = ['elephant', 'lion', 'tiger', "giraffe", "monkey", 'dog'] # create new list print(animals) animals[1:3] = ['cat'] # replace 2 items -- 'lion' and 'tiger' with one item -- 'cat' print(animals) animals[1:3] = [] # remove 2 items -- 'cat' and 'giraffe' from the list print(animals) animals[0:4] = [] print(animals) 산출물 (Output)['elephant', 'lion', 'tiger', 'giraffe', 'monkey', 'dog'] ['elep..
2016. 3. 7.
list_operations.py
animals = ['elephant', 'lion', 'tiger', "giraffe"] # create new list print(animals) animals += ["monkey", 'dog'] # add two items to the list print(animals) animals.append("dino") # add one more item to the list using append() method print(animals) animals[6] = 'dinosaur' print(animals) 산출물 (Output) ['elephant', 'lion', 'tiger', 'giraffe'] ['elephant', 'lion', 'tiger', 'giraffe', 'monkey', 'dog']..
2016. 3. 7.
lists.py
squares = [1, 4, 9, 16, 25] # create new list print(squares) print(squares[1:4]) 산출물 (Output)[1, 4, 9, 16, 25] [4, 9, 16] * A list is a data structure you can use to store a collection of different pieces of information under a single variable name. A list can be written as an array of comma-separated values (items) between square brackets, e.g. lst = [item1, item2]. Lists might contain items of..
2016. 3. 6.