User Tools

Site Tools


python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python [2021/08/05 07:47] – [Property decorator and setter decorators] utedasspython [2022/12/05 16:26] (current) utedass
Line 20: Line 20:
   * Vad är generators, hur fungerar yield   * Vad är generators, hur fungerar yield
   * Vem fan kom på syntaxen ''mylist = [x*x for x in range(3)]'' och när kan den användas?   * Vem fan kom på syntaxen ''mylist = [x*x for x in range(3)]'' och när kan den användas?
 +  * ^ Verkar vara [[https://www.w3schools.com/python/python_lists_comprehension.asp|List comprehensions]]
 ====== Cheat sheet ====== ====== Cheat sheet ======
  
Line 30: Line 30:
 populated_tuple = (1, 2, "Kalle", 4.32) populated_tuple = (1, 2, "Kalle", 4.32)
 singleton_tuple = (3,) singleton_tuple = (3,)
 +print(populated_tuple[2]) # Prints Kalle
  
 # Ranges are also immutable # Ranges are also immutable
Line 57: Line 58:
 all_keys = list(my_dict) all_keys = list(my_dict)
 leet = my_dict['shit'] leet = my_dict['shit']
 +
 +# Dictionaries can be unpacked and used as arguments to a function
 +dude = {a: 4, b: 5}
 +function_that_takes_a_and_b(**dude)
  
 # Set types must contain hashable objects. They are not ordered and cannot be indexed # Set types must contain hashable objects. They are not ordered and cannot be indexed
Line 99: Line 104:
  
  
-====== Parser ======+====== Argument parser ======
  
 <code python> <code python>
python.1628149648.txt.gz · Last modified: 2022/09/12 00:30 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki