---
# System prepended metadata

title: Pythonお勉強　メモ
tags: [python]

---

# Pythonお勉強　メモ
###### tags: `python` 
#### 集合のメモ
```python=
#集合覚えましょ！ 集合
A = { 1,2,3,4}
B = { 3,4,5,6}

union = A|B #{1, 2, 3, 4, 5, 6}
intersection = A & B #{3, 4}
differnce_AB = A - B #{1, 2}
difference_BA = B - A #{5, 6}
symmetric_diff A ^ B #{1, 2, 5, 6}
```

#### FullPathから文字を抜き取りインクリメントする練習
```python=
#splitの使い方メモ
#ファイルOpenダイアログ
from tkinter import filedialog
file_name =  filedialog.askopenfilename()

#split
file_from = "W:/mov/practice_v005.mp4"
split_path = file_from.split("/") # [ 'W:', 'mov', 'practice_v005.mp4']
filenames = split_path[-1] # practice_v005.mp4 を取得。
filename = filenames.split(".")[0] #practice_v005
oldVersion = filename.split("_")[-1]#v005
#print(oldVersion)
#先頭'v'を取る
versionNum = oldVersion[1:] #005
#print(versionNum)
increment = int(versionNum) + 1 #6
newVersion = "v{:03}".format(increment) #v006
file_to = file_from.replace(oldVersion,newVersion)
print(file_from)
print(file_to) #practice_v006.mp4 
```
#### Noneの使い方
```python=
#None
data = None
if data is None:
    print("data is None")
```
#### List zipの使い方 →　tupleで纏めてくれる
```python=
import itertools

iter1 =(1,2,3,4,5,6,7)
iter2 = [1,2]
iter3 = list(range(7))

for z in itertools.zip_longest(iter1,iter2,iter3, fillvalue="ichio"):
    print(z)

＃結果
(1, 1, 0)
(2, 2, 1)
(3, 'ichio', 2)
(4, 'ichio', 3)
(5, 'ichio', 4)
(6, 'ichio', 5)
(7, 'ichio', 6)
```