전체 글
-
[Python] - N진수 표현 및 Ascii개발/Python 2022. 7. 27. 18:07
Python 진법 변환 1. N Base -> 10 Base value is A number or a string that can be converted into an integer number base is A number representing the number format. Default value − 10 Syntax - int(value, base) # N base to 10 base print(int('101',2)) > 5 print(int('202',3)) > 20 print(int('ADF',16)) > 2783 2. 10 Base -> 2 / 8 / 16 Base bin(), oct(), hex() function support # 2base print(bin(11)[2:]) > 10..
-
[Python] - Regular expression개발/Python 2022. 7. 27. 17:29
Regular Expression 1.meta characters . ^ $ * + ? { } [ ] \ | ( ) 1.1) character class [] regular expression between [ and ] is matching characters '-' operator mean From - To ( [0-5] -> [012345] ) '^' operator mean Not '.' operator mean all characters except \n '*' operator mean repeat characters 0~N ( N maybe 2000000000 because memory limit ) '+' operator mean repeat characters 1~N {m,n} operat..
-
[Python] - Sort / Reverse개발/Python 2022. 7. 27. 15:26
1. Sort Only List(In-place) Reverse = [::-1] a = [1,5,2,4] a.sort() > [1,2,4,5] # a.sort() -> a[::-1] a.sort(reverse=True) > [5,4,2,1] 2. Sorted Use Iterable Object A simple ascending sort and returns a new sorted list key parameter call function for list element #iterable dict temp = {1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'} sorted(temp) > [1, 2, 3, 4, 5] sorted(temp.items()) > [(1, 'D'), (2, 'B..
-
[Python] - Iterators개발/Python 2022. 7. 27. 15:01
Iterators An iterator is an object that contains a countable number of values. An iterator is an object that can be iterated upon, meaning that you can traverse through all the values. Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__(). iterable Lists, tuples, dictionaries, and sets are all iterable obje..
-
[Python] - Function , Lambda개발/Python 2022. 7. 27. 14:37
1. Function A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function. A function can return data as a result. A function Object is mutable(User classes are considered mutable) - https://stackoverflow.com/questions/12076445/are-user-defined-classes-mutable # create function def test(): return "test" # call function test() 1-1) *args ..
-
[Python] - Powerful Function개발/Python 2022. 7. 27. 14:12
1. Range range는 range(start, end, step) Option range's result start_number ~ end-1 collection list(range(5,10)) > [5, 6, 7, 8, 9] list(range(10,20,2)) > [10, 12, 14, 16, 18] 2. Enumerate Use repeat Loop we need to check times Loop return tuple( index , element ) for i, v in enumerate(t): print("index : {}, value: {}".format(i,v)) """ index : 0, value: 1 index : 1, value: 5 index : 2, value: 7 in..
-
[Python] - Set개발/Python 2022. 7. 27. 13:05
Set set은 수학에서 이야기하는 집합과 비슷합니다. Not order, unique value mutable Object 1. Syntax s = set() s = set([1,3,5,7]) similar dictionary, but no key . Only value value is not immutable s = {"1", 3, 5, (1,3)} # Error s = {"1", 3, 5, [1,3]} s = {"1", 3, 5, {1,3}} s = {"1", 3, 5, frozenset([1,3,4])} 2. Change Element k = {100, 105} # insert value k.add(50) # multiple value insert k.update([3, 4, 5]) # delet..
-
[Python] - Dictionary개발/Python 2022. 7. 27. 12:17
Dictionary type is immutable key and mutable value mapping not sorted set No index , so access the key Syntax # Default type {"a" : 1, "b":2} e = {} f = dict() newdict = dict( alice = 5, bob = 20, tony= 15, suzy = 30) Key is not allowed mutable key like list , set , dict # Error case a = { {1, 3}: 5, {3,5}: 3} #set a = {[1,3]: 5, [3,5]: 3} #list a = { {"a":1}: 5, "abc": 3} #dict # Key immuttable..