본문 바로가기

부스트캠프 AI Tech/Python

(12)
String String sequential data type 1 char = 1 byte Raw string raw_string = "Python \n Java \n C" print(raw_string) Python Java C raw_string = r"Python \n Java \n C" print(raw_string) Python \n Java \n C Call by Value vs Call by Reference Call by Object Reference 객체의 주소가 함수로 전달되는 방식 새로운 객체를 만들 경우 영향을 주지 않음 def test(t): print(t) # 10 t = 20 # 새로운 객체가 생성, x != t print(t) # 20 x = 10 test(x) print(x) # 10T..
Conditionals and loops x is y : 메모리 주소 비교 x == y : 값만 비교 python에서 -5 ~ 256은 정적메모리 공간에 저장한 후 해당 값을 가지는 변수를 일괄적으로 할당 x = -5, y = -5 x is y : True x = -6, y = -6 x is y : Falseboolean_list = [True, False, True] all(boolean_list) : False any(boolean_list) : True
Function and Formatting Function def 함수 이름(parameter #1, ... ): 수행문 #1(statement) 수행문 #2(statement) return parameter, argument Formatting %-format : "%datatype"%(variable) print("I eat %d apples. " % 3) str.format() : "{datatype}".format(argument) print("My name is {0} and {1} years old.".format(name,age)) fstring : f"{var name}" print(f"hello, {name}. You are {age}.")
Variable & Memory Variable 각 변수는 메모리 주소를 가지고, 변수의 값은 그 메모리 주소에 할당 폰노이만 아키텍쳐 알파벳, 숫자, 언더스코어(_)로 선언 가능 대소문자 구분, 예약어(for, if, else 등) 사용 불가 변수 선언 규칙 Primitive Data Type integer, float, string, boolean Dynamic Typing 코드 실행시점(runtime)에 데이터의 type을 결정 List indexing [start:end:step] deepcopy