python/python(2)
-
[python] class ; single underscore, double underscore
When we are making some class, we often see the _ or __ in class.But what do they mean?Actually, _ means it is intended to be used inside the class, but it's not enforced.__ means it is also intended to be used inside the class, but with stronger protection. In this case, __hidden naming triggers Name Mangling, so the __hidden is gonna change to _ClassName__hidden. class nn: def __init__(sel..
2025.08.17 -
[Python] Module에대한 이해
Module이란? 하나의 source code file을 그냥 module이라고 한다. 이 source file에는 함수가 들어있거나 프로그램의 일부를 담당할 때 module이라고 부르기도 한다. 어떤 함수를 만들었는데 한 번만 쓰고 버리기 아깝다면?. py 파일을 만들어서 다음에 쓰고 싶을 때 불러오면 된다. 이런 식으로 module을 사용한다. Module을 만들어보자. # module_ex.py def add_two_values(a,b): return a + b def multiple_two_values(a,b): return a * b위의 두 함수를 module_ex.py 파일로 저장해 둔다. 이제 add_two_values, multiple_two_values를 다른 파일에서 불러와 써보자..
2025.07.12