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
- https://m.blog.naver.com/tt2t2am1118/221010125300
- sql
- Porject
- js
- promise
- setTimeout()
- prj
- slow and steady
- ๊ฒ์
- JS #ํ๋ก์ ํธ
- json
- https://youtube.com/playlist?list=PLuHgQVnccGMA5836CvWfieEQy0T0ov6Jh&si=FTaYv8m21EhO-A2K
- db
- async
- await
- eport
- addEventListener
- ajax
- webpack
- Import
- mysql
- ์ฐธ๊ณ ๋ธ๋ก๊ทธ
- object
- ๋น๋๊ธฐ
- execCommand
- Project
- callback
- ํผํ
- database
- ๋๊ธฐ
Archives
- Today
- Total
C-log
Welcome to Python : ํจ์ ๋ณธ๋ฌธ
728x90
- ํจ์ : https://hi-code.tistory.com/119
- ์ฌ์ฉ์ ์ ์ถ๋ ฅ : https://hi-code.tistory.com/120
- ํ์ผ ์ฝ๊ณ ์ฐ๊ธฐ : https://hi-code.tistory.com/121
- ํ๋ก๊ทธ๋จ์ ์ ์ถ๋ ฅ : https://hi-code.tistory.com/122
Title | Code | Console |
ํจ์ | ||
ํจ์์ ๊ธฐ๋ณธ ๊ตฌ์กฐ |
def add(a, b): return a+b
a = 3
b = 4
c = add(a, b)
print(c)
|
7 |
def add(a, b): print("%d, %d์ ํฉ์ %d์
๋๋ค." % (a, b, a+b))
return a+b
add(3, 4)
|
3, 4์ ํฉ์ 7์ ๋๋ค. | |
์ฌ๋ฌ ๊ฐ์ ์ ๋ ฅ๊ฐ์ ๋ฐ๋ ํจ์ ๋ง๋ค๊ธฐ |
def add_many(*args): result = 0
for i in args:
result = result + i
return result
result = add_many(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
print(result)
|
55 |
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_mul = add_mul('add', 1, 2, 3, 4, 5)
print(result_mul)
result_add = add_mul('mul', 1, 2, 3, 4, 5)
print(result_add)
|
15 120 |
|
ํค์๋ ๋งค๊ฐ๋ณ์. kwargs |
def print_kwargs(**kwargs): print(kwargs)
print_kwargs(a=1)
print_kwargs(name='foo', age=3)
|
{'a': 1} {'name': 'foo', 'age': 3} |
ํจ์์ ๋ฆฌํด๊ฐ์ ํ์ฉ |
def add_and_mul(a, b):
return a+b, a*b
result = add_and_mul(3, 4) #ํฌํ ํํ๋ก ๋ฐํ
print(result)
|
(7, 12) |
def add_and_mul(a, b):
return a+b, a*b
result1, result2 = add_and_mul(3, 4)
print(result1, result2) # result1 7, result2 12
|
7 12 | |
def say_nick(nick): if nick == '๋ฐ๋ณด':
return print('๋ฐ๋ณด๋์')
print("๋์ ๋ณ๋ช
์ %s์
๋๋ค." % nick)
say_nick("์ผํธ") # if๋ฌธ์ ์กฐ๊ฑด์ด ๋ง์ง ์์์ print
say_nick("๋ฐ๋ณด") # if๋ฌธ์ ์กฐ๊ฑด์ด ๋ง์์ return
|
๋์ ๋ณ๋ช
์ ์ผํธ์
๋๋ค. ๋ฐ๋ณด๋์ |
|
๋งค๊ฐ๋ณ์ ์ด๊น๊ฐ ์ค์ ํ๊ธฐ |
def say_myself(name, age, man=True): print("๋์ ์ด๋ฆ์ %s์
๋๋ค." % name)
print("๋์ด๋ %d์ด์
๋๋ค." % age)
if man:
print("๋จ์์
๋๋ค.")
else:
print("์ฌ์์
๋๋ค.")
say_myself("๋ฐ์์ฉ", 27)
say_myself("๋ฐ์์ฉ", 27, True)
|
๋์ ์ด๋ฆ์ ๋ฐ์์ฉ์
๋๋ค. ๋์ด๋ 27์ด์ ๋๋ค. ๋จ์์ ๋๋ค. ๋์ ์ด๋ฆ์ ๋ฐ์์ฉ์ ๋๋ค. ๋์ด๋ 27์ด์ ๋๋ค. ๋จ์์ ๋๋ค. |
def say_myself(name, man=True, age): #์ ์๋ ๋งค๊ฐ๋ณ์ ๋ค์ ์ผ๋ฐ ๋งค๊ฐ๋ณ์๊ฐ ์ฌ ์ ์๋ค.
print("๋์ ์ด๋ฆ์ %s์
๋๋ค." % name)
print("๋์ด๋ %d์ด์
๋๋ค." % age)
if man:
print("๋จ์์
๋๋ค.")
else:
print("์ฌ์์
๋๋ค.")
say_myself("๋ฐ์์ฉ", 27)
|
File "...\Quiz.py", line 1 def say_myself(name, man=True, age): ^^^ SyntaxError: non-default argument follows default argument |
|
retrun ์ฌ์ฉํ๊ธฐ |
a = 1 def vartest(a):
a = a+1
return a
a = vartest(a)
print(a)
|
2 |
global ์ฌ์ฉํ๊ธฐ |
a = 1 def vartest():
global a
a = a+1
vartest()
print(a)
|
2 |
lambda ์์ฝ์ด |
def add(a, b): return a+b result = add(3, 4)
print(result)
|
7 |
728x90
'๐Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Welcome to Python : ํ์ผ ์ฝ๊ณ ์ฐ๊ธฐ (0) | 2023.07.13 |
---|---|
Welcome to Python : ์ฌ์ฉ์ ์ ์ถ๋ ฅ (0) | 2023.07.13 |
Welcome to Python : for๋ฌธ (0) | 2023.07.09 |
Welcome to Python : while๋ฌธ (0) | 2023.07.09 |
Welcome to Python : if๋ฌธ (0) | 2023.07.09 |
Comments