목록Programming/Python(파이썬) (44)
59doit
가변함수 튜플확인 def test(*arg) : print(type(arg)) test(1,2) # 튜플형 def Func1 (name, *names) : print(name) print(*names) Func1("가","나","다") # # 가 # 나다 튜플형 _ 한줄로 print def Func1 (name, *names) : print(name,end=' ') print(*names) Func1("가","나","다") # # 가 나 다 end 뒤에 쌍따옴표 말고 ->('') 여야 한줄에 나옴 print는 기본적으로 한줄띄어서 출력된다 딕트형 def emp_func(name,age,**other) : print(name) print(age) print(other) emp_func("JAIN", 25 ..
dataset = list(range(1,7)) print(dataset) # [1, 2, 3, 4, 5, 6] print('len=',len(dataset)) # len= 6 print('sum=',sum(dataset)) # sum= 21 print('max=',max(dataset)) # max= 6 print('min=',min(dataset)) # min= 1 import 함수 ; 외부 모듈을 포함시켜야 사용 할 수 있는 함수 1) 모듈명.함수() 수학/통계 함수 statistics모듈을 import 해야한다 즉, 평균,중위수는 내장함수가 아니기 때문에 모듈을 import해야한다 dataset = list(range(1,7)) print(dataset) # [1, 2, 3, 4, 5, 6] im..
객체 주소 복사 name = ["a","b","c"] print ('name address=',id(name)) name2 = name print('name2 address=',id(name2)) > 주소 동일 name address = name2 address > 내용 동일 print(name) #>['a', 'b', 'c'] print(name2) #>['a', 'b', 'c'] 얕은 복사-원본수정 name2[0] = "d" #name2의 첫번째자리 a 를 d로 수정 print(name) # ['d', 'b', 'c'] print(name2) # ['d', 'b', 'c'] 깊은복사-내용동일 주소다름 import copy #copy 모듈 넣어야함 name3 = copy.deepcopy(name) # ..
리스트내포; list 안에 for , if 사용하는 문법 형식1) 변수=[실행문 for 변수 in 열거형객체] x=[1,2,3,4,5] print (x**2) # TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' lst = [y**2 for y in x] print(lst) # [1, 4, 9, 16, 25] 직접 곱하면 Error 발생 하여 x객체의 원소를 하나씩 y변수에 넣어서 **2 해주어야 한다. 형식2) 변수=[실행문 for 변수 in 열거형객체 if 조건문] ; 조건문이 true 일때 ex) 1~10까지의 수에서 2의 배수 추출 lst = list(range(1,11)) # 1~10까지의 수 lst2=[i*2 fo..