전역변수 함수 외부 선언. 함수 내부 참조 가능. 지역변수 함수 내부 선언. 함수 내부 참조 가능. 함수 종료시 삭제. 글로벌 변수 함수 내부, 외부 선언 가능. 함수 내부 참조 가능. 함수 내부 변경 가능. 정적 변수 클래스 내부에 선언된 변수. a = 5 #전역 변수 b = 10 #전역 변수 def ex(): a = 10 #지역 변수 global b #글로벌 변수로 재정의 b = 15 print("함수 안에서 선언된 지역 변수 a: {}".format(a)) print("함수 안에서 선언된 글로벌 변수 b: {}".format(b)) print("함수 바깥에서 선언된 전역 변수 a: {}".format(a)) #5(전역 변수) print("함수 바깥에서 선언된 전역 변수 b: {}".format(b)..
클래스 상속 class Person: def __init__(self, name, age): self.name = name self.age = age def get_name(self): print("My name is {}".format(self.name)) def get_age(self): print("I'm {} years old".format(self.age)) class Student(Person): #부모 클래스를 상속 받으면 자동으로 변수와 기본 함수도 따라 온다. def __init__(self, name, age, GPA): super(Student, self).__init__(name, age) #부모 클래스의 메소드 호출 #단순히 super().__init__(name, age)라고 적..