๋ฐ์ํ
Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- ์ด๊ฒ์ด ์ทจ์ ์ ์ํ ์ฝ๋ฉํ ์คํธ๋ค
- ํ์ ๋ณ์
- Do it
- mysql
- ๋ฐ์ค๊ทธ๋ํ
- Extended Slices
- matplotlib
- ๋ธ๋ผ์ฐ์ ์คํ
- ์ ํ ํฌ ํ์ด์ฌ
- ์ด์ง์ ๋ณํ
- dacon
- ํ๋ก๊ทธ๋๋จธ์ค
- sql
- BFS
- np.zeros_like
- ์๋ฐ
- PYTHON
- Do_it
- java
- jdbc
- MacOS
- ๋ค์ต์คํธ๋ผ ์๊ณ ๋ฆฌ์ฆ
- ์ต์
- ์ฐธ์กฐ ๋ณ์
- ์์ด
- DFS
- ๋ฐฑ์ค
- ์ง ๊ฐ ์์ธก ๋ถ์
- 2BPerfect
- ํฉํ ๋ฆฌ์ผ ์ง๋ฒ
Archives
- Today
- Total
๐ฆ ๊ณต๋ฃก์ด ๋์!
python_re_study...2 ๋ณธ๋ฌธ
- ์กฐ๊ฑด์์ฐธ์ด๋ฉด success ๊ฑฐ์ง์ด๋ฉด failure
-
message = "success" **if** score >= 60 **else** "failure"
- ์ฐธ์ด๋ฉด success ๊ฑฐ์ง์ด๋ฉด failure
- ๋ฐ๋ณต๋ฌธ
- ํ๋กฌํํธ ๋ง๋ค๊ธฐ
prompt = """ ... 1. Add ... 2. Del ... 3. List ... 4. Quit ... ... Enter number: """
>>> number = 0 >>> while number != 4: ... print(prompt) ... number = int(input()) ... 1. Add 2. Del 3. List 4. Quit Enter number:
- ์์
>>> a = [(1,2), (3,4), (5,6)] >>> for (first, last) in a: ... print(first + last) ... 3 7 11
>>> result = [num * 3 for num in a] >>> print(result) [3, 6, 9, 12]
- ํจ์
- *args ๋งค๊ฐ๋ณ์
>>> def add_mul(choice, *args): ... if choice == "add": ... result = 0 ... for i in args: ... result = result + i ... elif choice == "mul": ... result = 1 ... for i in args: ... result = result * i ... return result >>> result = add_mul('add', 1,2,3,4,5) >>> print(result) 15 >>> result = add_mul('mul', 1,2,3,4,5) >>> print(result) 120
- **kwargs ํค์๋ ๋งค๊ฐ๋ณ์
>>> def print_kwargs(**kwargs): ... print(kwargs) ... >>> print_kwargs(a=1) {'a': 1} >>> print_kwargs(name='foo', age=3) {'age': 3, 'name': 'foo'}
- global
a = 1 def vartest(): global a a = a+1 vartest() print(a)
- lambda
-
>>> add = lambda a, b: a+b >>> result = add(3, 4) >>> print(result) 7 ์ํ ๋์ผ >>> def add(a, b): ... return a+b ... >>> result = add(3, 4) >>> print(result) 7
lambda ์์ฝ์ด๋ก ๋ง๋ ํจ์๋ return ๋ช
๋ น์ด๊ฐ ์์ด๋ ๊ฒฐ๊ด๊ฐ์ ๋๋ ค์ค๋ค.
ํ์ผ ์ฝ๊ณ ์ฐ๊ธฐ
f = open("์ํ์ผ.txt", 'w')
f.close()
r | ์ฝ๊ธฐ๋ชจ๋ - ํ์ผ์ ์ฝ๊ธฐ๋ง ํ ๋ ์ฌ์ฉ |
w | ์ฐ๊ธฐ๋ชจ๋ - ํ์ผ์ ๋ด์ฉ์ ์ธ ๋ ์ฌ์ฉ |
a | ์ถ๊ฐ๋ชจ๋ - ํ์ผ์ ๋ง์ง๋ง์ ์๋ก์ด ๋ด์ฉ์ ์ถ๊ฐ ์ํฌ ๋ ์ฌ์ฉ |
๋ง์ฝ ์ํ์ผ.txt ํ์ผ์ C:/doit ๋๋ ํฐ๋ฆฌ์ ์์ฑํ๊ณ ์ถ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์์ฑํด์ผ ํ๋ค.
# writedata.py
f = open("C:/doit/์ํ์ผ.txt", 'w')
for i in range(1, 11):
data = "%d๋ฒ์งธ ์ค์
๋๋ค.\\n" % i
f.write(data)
f.close()
for i in range(1, 11):
data = "%d๋ฒ์งธ ์ค์
๋๋ค.\\n" % i
print(data)
- ์ธ๋ถ ์ ์ฅ ํ์ผ ์ฝ๋ ๋ฒ
- ํ ์ค ์ถ๋ ฅ
# readline_test.py f = open("C:/doit/์ํ์ผ.txt", 'r') line = f.readline() print(line) f.close()
- ์ ๋ถ ์ถ๋ ฅ
# readline_all.py f = open("C:/doit/์ํ์ผ.txt", 'r') while True: line = f.readline() if not line: break print(line) f.close()
- ์ฐธ๊ณ (์ ๋ ฅ ๊ฐ์ ์ด๋ ๊ฒ๋ ๋๋ค)
-
while True: data = input() if not data: break print(data)
- readlines
f = open("C:/doit/์ํ์ผ.txt", 'r') lines = f.readlines() for line in lines: print(line) f.close()
- ์ค ๋ฐ๊ฟ(\n) ๋ฌธ์ ์ ๊ฑฐํ๊ธฐ
f = open("C:/doit/์ํ์ผ.txt", 'r') lines = f.readlines() for line in lines: line = line.strip() # ์ค ๋์ ์ค ๋ฐ๊ฟ ๋ฌธ์๋ฅผ ์ ๊ฑฐํ๋ค. print(line) f.close()
- ํ์ผ ์ ๋ด์ฉ ์ถ๊ฐํ๊ธฐ
# adddata.py
f = open("C:/doit/์ํ์ผ.txt",'a')
for i in range(11, 20):
data = "%d๋ฒ์งธ ์ค์
๋๋ค.\\n" % i
f.write(data)
f.close()
- with ๋ฌธ ์ด์ฉ
with open("foo.txt", "w") as f:
f.write("Life is too short, you need python")
- import sys
#sys1.py
import sys
args = sys.argv[1:]
for i in args:
print(i)
C:\\doit>python sys1.py aaa bbb ccc
aaa
bbb
ccc
#sys2.py
import sys
args = sys.argv[1:]
for i in args:
print(i.upper(), end=' ')
C:\\doit>python sys2.py life is too short, you need python
LIFE IS TOO SHORT, YOU NEED PYTHON
โ
์ฐธ๊ณ : https://wikidocs.net/book/1
์ ํ ํฌ ํ์ด์ฌ
** ์ ํ ํฌ ํ์ด์ฌ ์คํ๋ผ์ธ ์ฑ (๊ฐ์ ํ) ์ถ๊ฐ !! (2019.06) ** * [์ฑ ๊ตฌ์ ์๋ด](https://wikidocs.net/4321) ์ด ์ฑ ์ ํ์ด์ฌ ...
wikidocs.net
๋ฐ์ํ
'Development > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
python_re_study...4 (0) | 2021.12.18 |
---|---|
python_re_study...3 (0) | 2021.12.17 |
python_re_study...1 (0) | 2021.12.15 |
Python Library(os) (0) | 2021.12.07 |
Pythonic Code (0) | 2021.12.01 |
Comments