41 키워드

전달값이 많은데, 필요할 때만 True로 변경하는방
42 가변인자
def visit ( today, customer1, customer2 .... )
가변인자(개수가 바뀔 수 있는 인자) 사용
def visit ( today, *customers )

가변인자는 한 번만 쓸 수 있다 def function(a, *b, *c ) xxxxxxxxx
44강 전역변수
message="하이"
print(message)
def no_secret():
message="흐흐" #이건 지역변수임
print(message)
def no_secret():
global message="흐흐" #전역변수 값 변경/수정가능
print(message)
46 사용자입출력 ,파일입출력
num=input("총 몇분이세요?")
입력값은 모두 문자열 형태임
num=int( input("총 몇분이세요?") )
open(파일명, 열기모드, encoding='인코딩')
<열기모드>
r: read(읽기)
a: append(이어서 쓰기)
w: write(쓰기)
f=open('list.txt' , 'w' , 'encoding="utf8")
f.write('김xx\n')
f.write('정xx\n')
f.write('허xx\n')
f.close()
f=open('list.txt' , 'r' , 'encoding="utf8")
contents=f.read()
print(contents)
f.close()
f=open('list.txt' , 'r' , 'encoding="utf8")
contents=f.read()
print(contents)
f.close()
f=open('list.txt' , 'r' , 'encoding="utf8")
for line in f :
print(line,end='')
print(contents)
f.close()
47강 with
close()함수를 호출할 필요 없이 하는것!
f=open('list.txt','w','encoding='utf8')
이걸
with open('list.txt','w','encoding='utf8') as f :
f.write('김xx\n')
f.write('정xx\n')
f.write('허xx\n')
f.close()
with f=open('list.txt' , 'r' , 'encoding="utf8") as f:
contents=f.read()
print(contents)
f.close()
48,49 클래스의 정의
class 클래스명 :
정의
class BlackBox:
pass
b1=BlackBox()
b1.name="후후" #객체에 변수선언
print(b1.name)
print(isinstance(b1,BlackBox)) #인스턴스가 맞나 확인하는거 , True라고 뜸 이러면
50 __init__
class BlackBox:
def __init__(self,name,price):
self.name=name
self.price=price
b1=BlackBox('까망이',20000)
print(b1.name , b1.price)
b2=BlackBox('하양이',120000)
print(b2.name , b2.price)
'파이썬 기초' 카테고리의 다른 글
| [PYTHON] split() , map() 에 대해 정리 (0) | 2025.03.30 |
|---|---|
| [파이썬] 모르는 것을 다 적어보자 [20강-29강] (0) | 2024.12.22 |
| [파이썬] 몰랐던거만 적어보자 (11-20강) (0) | 2024.12.21 |
| [파이썬] 몰랐던거만 적어보자 (1-10강) (1) | 2024.12.07 |
| [파이썬 기초] 리스트의 기본적인 함수2 (2) | 2023.01.12 |