2020/0719 For study output using PyQ Keep a record of your own learning + aim for something that people in the same position can read.
In principle, be aware of the following in learning. ・ Do not just do the basics, but start creating simple applications and tools as soon as the basics are completed. ・ If you don't understand something, do a quick search, and if you don't understand it, proceed. ・ Be aware that programming is nothing more than a tool for making what you want to make. ・ Set goals clearly and study while being aware of the period.
Small goal End the PyQ curriculum. Now: Learn Containers
Big goal Create an application in Python.
A tuple is a type of data that manages multiple elements such as lists and dictionaries.
・ Elements cannot be added / deleted / changed ・ () And, are trademarks ・ Memory used is smaller than the list * ・ In many cases, tuples can be calculated faster than lists * ・ Can be used with list and dictionary types -Data type can be changed with list () and tuple () functions
Problem: Please output data with customer ID of 10 or less and sales amount of 100 yen or more.
code """ sales = ((1, 100), (2, 30), (7, 150), (11, 120), (10, 100))
for sale in sales: if sale[0] <= 10 and sale[1] >= 100: print(sale)
"""
output """ (1, 100) (7, 150) (10, 100) """
A set is a list-like data structure, but with the following characteristics:
・ Literals use curly braces such as {'art','box'}. ・ Only immutable (immutable) items can be entered. ・ You can have only one of the same item. Even if you add more than one, it will be one. -There is no order. If acquired as iterable, the order may change each time it is executed. -There are operations between sets. -Searching is faster than the list.
Set method (addition / update / deletion)
add(item) Add an item.
update(iterable) Add all the elements of the iterable iterable.
clear() Delete all elements.
pop() Deletes any element and returns it.
remove(item) Delete the item. If item does not exist, an error (KeyError) will occur.
discard(item) Delete the item. No error will occur even if item does not exist.
""" items = {'art'} print("items:", items)
result = items.pop() print("items.pop():", result) print("items:", items)
items.update(["egg", "fog"]) print("items.update(['egg', 'fog'])") print("items:", items)
items.clear() print("items.clear()") print("items:", items)
items.add("doll") print("items.add('doll')") print("items:", items)
items.remove("doll") print("items.remove('doll')") print("items:", items) """
items: {'art'} items.pop(): art items: set() items.update(['egg', 'fog']) items: {'fog', 'egg'} items.clear() items: set() items.add('doll') items: {'doll'} items.remove('doll') items: set()
Recommended Posts