🐍 파이썬/파이썬 기본 문법
-
[class] python-specific special method🐍 파이썬/파이썬 기본 문법 2022. 7. 27. 11:44
By Default, Printing An Object Is Not Helpful. Redefine __str__ method to Improve Output. Goal of havung __str__ is to create human-readable representation of an object. Why doesn’t it work in collections? Collections use __repr__ to print the contained objects ! Goal of __repr__is to create unambiguous representation of an object. By Default, Different Objects Are Not Equal Redefine __eq__ to A..
-
[OOP] class 클래스 개념 및 구성요소🐍 파이썬/파이썬 기본 문법 2022. 7. 27. 11:30
What is "Object-oriented" programming? •"Object-orientation" is just one of many programming paradigms : Our world is made up of "things", so it is a good model of the world! •Practical considerations: -Facilitates testing(we can test the classes separately) -Encourages reuse(we can reuse classes defined by other people) -Users don’t need to know the inner workings of a class, they just rely on ..
-
[list] reference and copy (aliasing and clone)🐍 파이썬/파이썬 기본 문법 2022. 7. 19. 06:42
Reference : multiple variables can point same object x = [1,2,3,4,5] y = x # this is called aliasing print(y[1]) # 2 y[1] = 0 print(y) # [1,0,3,4,5] print(x) # [1,0,3,4,5] copy a = [1,2,3] b = a[:] # copy or clone print(b) # [1,2,3] a[0] = 10 print(a) # [10,2,3] print(b) # [1,2,3] modifing a does not affect b Equality and Identity Operators == checks, if two objects are equal is checks, if two o..
-
[List] 자주쓰이는 리스트 메소드 정리🐍 파이썬/파이썬 기본 문법 2022. 7. 19. 06:27
1. concatenate # 1. use + operation a = [1,2,3] b = [4,5] c = a+b # [1,2,3,4,5] # 2. use .append method x = [1,2,3] y = [4,5] x.append(y) # [1,2,3,[4,5]] # 3. use .extend method x = [1,2,3] y = [4,5] x.extend(y) # [1,2,3,4,5] 2. delete the value l = [1,2,3,4,5] # 1. using pop() l.pop() # return 5, l=[1,2,3,4] # 2. delete by index using .del method del(l[0]) #return None, l=[2,3,4,5] # 3. delete ..
-
[concept] list vs tuple🐍 파이썬/파이썬 기본 문법 2022. 7. 19. 06:16
List and Tuple -Both are ordered set of values (or elements), where each value is identified by an index -The contained values can be of any type and a single list can contain mixed types -The main difference between the two data structures is that lists are mutable and tuples are immutable: means in case of tuple, you cannot modify (update value) once you created it
-
[Variable scope] global scope vs function scope🐍 파이썬/파이썬 기본 문법 2022. 7. 18. 08:35
- when you create a variable outside a function, we say the variable was defined inside the global scope - when you define a variable inside a function, it is available in the function scope - variables that are defined inside a function cannot be accessed from outside of the function x = 10 # gloabl scope def f(): x = 20 # function scope y = 30 print (x) print (x) # 10 f() # 20 this does not ch..
-
what is first class object?🐍 파이썬/파이썬 기본 문법 2022. 7. 18. 08:27
being a first class object means ... •can be passed as arguments to other functions •can be returned as values from other functions •can be assigned to variables •can be stored in data structures In python, Functio is also first class object ! :D
-