OSDN Git Service

Regular updates
authorErik <erikgronwal@users.osdn.me>
Sat, 18 Sep 2021 14:55:06 +0000 (23:55 +0900)
committerErik <erikgronwal@users.osdn.me>
Sat, 18 Sep 2021 14:55:06 +0000 (23:55 +0900)
python.md

index 813a888..8750057 100644 (file)
--- a/python.md
+++ b/python.md
@@ -3,12 +3,17 @@ title: Python
 category: Python
 ---
 
-### Lists
+### Tuples (immutable)
+
+    tuple = ()
+
+### Lists (mutable)
 
     list = []
     list[i:j]  # returns list subset
     list[-1]   # returns last element
     list[:-1]  # returns all but the last element
+    *list      # expands all elements in place
     
     list[i] = val
     list[i:j] = otherlist  # replace ith to jth-1 elements with otherlist
@@ -34,12 +39,14 @@ category: Python
 
 ### Dict
 
+    dict = {}
     dict.keys()
     dict.values()
     "key" in dict    # let's say this returns False, then...
     dict["key"]      # ...this raises KeyError
     dict.get("key")  # ...this returns None
     dict.setdefault("key", 1)
+    **dict           # expands all k/v pairs in place
 
 ### Iteration
 
@@ -126,7 +133,7 @@ file.close()
 ```py
 print(file.read())  # read the entire file and set the cursor at the end of file
 print file.readline() # Reading one line
-file.seek(0, 0) # place the cursor at the beggining of the file
+file.seek(0, 0) # place the cursor at the beginning of the file
 ```
 
 ### Writing (overwrite)
@@ -158,4 +165,3 @@ with open("welcome.txt", "r") as file:
 
 # It closes the file automatically at the end of scope, no need for `file.close()`.
 ```
-