# ๐งญ SyntaxError: positioanl argument follows keyword argument

Min-Ho Leeยท2020๋ 6์ 25์ผ
1

## Learn Python

๋ชฉ๋ก ๋ณด๊ธฐ
11/22

Thursday_June_25
.
.
.
์์ ์ ๋ชฉ์ ๋ฌธ๋ฒ ์๋ฌ๋ฅผ ์ดํดํ๋ ค๋ฉด ๋จผ์  ๊ฐ๋์ ์ก์์ผ ํ๋ค.

# 1๏ธโฃ Positional Arguments

๊ธฐ๋ณธ์ ์ธ ํจ์์ Parameter์๊ฒ ๊ฐ์ ์ ๋ฌํด ์ฃผ๋ ๋ฐฉ์์ด๋ค.

def number(first, second, third):
print("First = ", first)
print("Second = ", second)
print("Third = ", third)

์ด๋ฐ ํจ์๋ฅผ ์ ์ํ ํ, ํธ์ถ์ ํ  ๋
Argument์์ ์ฃผ๋ ์์๋๋ก ๊ฐ์ด Parameter์๊ฒ ์ ๋ฌ์ด ๋๋ค.

number("st", "nd", "rd")

์คํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.

First =  st
Second =  nd
Third =  rd

๋ค์๊ณผ ๊ฐ์ด Argument๋ฅผ ์ฃผ๋ฉด

number(789, 456, 123)

์คํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.

First =  789
Second =  456
Third =  123

# 2๏ธโฃ Keyword Arguments

Parameter์๊ฒ ๊ฐ์ ์์๋๋ก ์ฃผ์ง ์๋ ๋์ ์
ํจ์์์ ์ ์๋ Parameter์ ์ด๋ฆ์ผ๋ก ๋ง์ถ์ด์ ๊ฐ์ ์ ๋ฌํด ์ฃผ๋ ๋ฐฉ์์ ๋งํ๋ค.

์ด ๋ฐฉ์์ ์ฅ์ ์ Parameter์ ์ด๋ฆ์ ๋ง์ถ์ด ์ฃผ๊ธฐ๋๋ฌธ์,
ํธ์ถ์ ํ๋ Argument๋ค์ ์์๊ฐ ๋ฐ๋์ด๋ ์๊ด์ด ์๋ค๋ ์ ์ด๋ค.

๊ทธ๋ฆฌ๊ณ  ์ด๋ฆ์ ๋ง์ถ์ด ๊ฐ์ ๋๊ธฐ๊ธฐ ๋๋ฌธ์ ์ด๋ค Parameter์ ์ด๋ค ๊ฐ์ ์ฃผ๋์ง ์ฝ๊ฒ ์ ์ ์๋ค.

def number(first, second, third):
print("First = ", first)
print("Second = ", second)
print("Third = ", third)

๋๊ฐ์ ์์ ์์ Keyword Argument ๋ฐฉ์์ ์จ๋ณด๊ฒ ๋ค.

number(third = "rd", first = "st", second = "nd")

์ด๋ ๊ฒ ์์๋ฅผ ๋ค์ฃฝ๋ฐ์ฃฝ ์์์ด๋ Parameter์ ์ด๋ฆ์ ๋ง์ถ์ด ๊ฐ์ ์ฃผ์๊ธฐ ๋๋ฌธ์

First =  st
Second =  nd
Third =  rd

์คํ ๊ฒฐ๊ณผ๋ ๊ตฟ์ด๋ค ๐

# 3๏ธโฃ Mixing 1๏ธโฃ + 2๏ธโฃ

Positional Argument ๋ฐฉ์๊ณผ Keyword Argument ๋ฐฉ์์ ์์ด ์ฐ๋ ๋ฐฉ์์ด๋ค.

์์ ๋ฅผ ํตํด ์ดํดํด๋ณด์.

def real_madrid(ramos, kroos, benzema, bale):
print("Ramos's Back Number = ", ramos)
print("Kroos's Back Number = ", kroos)
print("Benzema's Back Number = ", benzema)
print("Bale's Back Number = ", bale)

#### โฐ TMI Time

๋ผ๋ชจ์ค์ ๋ฑ๋ฒํธ๋ 4๋ฒ
ํฌ๋ก์ค์ ๋ฑ๋ฒํธ๋ 8๋ฒ
๋ฒค์ ๋ง์ ๋ฑ๋ฒํธ๋ 9๋ฒ
๋ฒ ์ผ์ ๋ฑ๋ฒํธ๋ 11๋ฒ์ด๋ค.

์๋ฌดํผ ๋ ๋ฐฉ์์ ์์ด์ ํจ์๋ฅผ ์ฌ์ฉํด ๋ณด์.

real_madrid(4, 8, benzema = 9, bale = 11)
real_madrid(4, 8, bale = 11, benzema = 9)

์ผ๋จ ํจ์์ ์ถ๋ ฅ๊ฐ์ ๋ ๋ค ๋ชจ๋ ๊ฐ๋ค.

Ramos's Back Number =  4
Kroos's Back Number =  8
Benzema's Back Number =  9
Bale's Back Number =  11

๊ทธ๋ฆฌ๊ณ  ์์์ 4์ 8์ Positional ๋ฐฉ์์ ์ฌ์ฉํ ๊ฒ์ด๊ณ ,
benzema์ bale์ Keyword ๋ฐฉ์์ ์ฌ์ฉํ ๊ฒ์ด๋ค.
๊ทธ๋์ ์์ ์ค๋ชํ๋ฏ, Keyword Argument ๋ฐฉ์์ ์์๊ฐ ์๊ด์ด ์๊ธฐ ๋๋ฌธ์, ์ฒซ ๋ฒ์งธ ์ค๊ณผ ๋ ๋ฒ์งธ ์ค์์ ๋ณด์ด๋๊ฒ ์ฒ๋ผ benzema์ bale์ ์๋ฆฌ๋ฅผ ๋ฐ๊ฟ๋ ์๊ด์ด ์๋ค.

## โ๏ธ SyntaxError: positioanl argument follows keyword argument

3๋ฒ์ Mixing ๋ฐฉ๋ฒ์ ์ฃผ์์ฌํญ์ด ์๋ค.

Keyword ๋ผ๋ฆฌ์ ์์๋ ์๊ด์ด ์์ง๋ง,
Positional๊ณผ Keyword๋ฅผ ์์ด ์ธ ๋์๋ ์์๊ฐ ์ค์ํ๋ค.

EX)

real_madrid(4, kroos = 8, 9, bale = 11)
real_madrid(ramos = 4, kroos = 8, 9, 11)

๋ ๋ฐฉ์ ๋ชจ๋ ๋ค ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.

SyntaxError: positioanl argument follows keyword argument

Keyword ๋ฐฉ์์ด Positional ๋ฐฉ์๋ณด๋ค ์์์ ์ฌ์ฉ๋๋ค๊ณ  ๋ฌ ์๋ฌ์ด๋ค.

๊ทธ๋ฅ ์์ด์ ์ฌ์ฉํ  ๋์๋ ๋ฌด์กฐ๊ฑด ์์ชฝ์ Positional ๋ฐฉ์์ ์จ์ค ํ, Keyword ๋ฐฉ์์ ์จ์ฃผ๋ฉด ๋๋ค.

๐ Rabbit can take a rest, but ๐ข turtle can't