코딩
-
[Python tutorial] 15. Lambda코딩/Python 2022. 12. 21. 17:16
Lambda Syntax: lambda arguments : expression x = lambda a : a + 10 print(x(5)) # 15 x = lambda a, b : a * b print(x(5, 6)) # 30 x = lambda a, b, c : a + b + c print(x(5, 6, 2)) # 13 def myfunc(n): return lambda a : a * n # myfunc는 lambda를 return mydoubler = myfunc(2) mytripler = myfunc(3) print(mydoubler(11)) # 22 print(mytripler(11)) # 33
-
[Python tutorial] 14. Functions코딩/Python 2022. 12. 21. 17:15
Functions def my_function(): print("Hello from a function") my_function() # call a function Arguments (args) def my_function(fname): print(fname + " Refsnes") my_function("Emil") Number of Arguments def my_function(fname, lname): # 2 args print(fname + " " + lname) my_function("Emil", "Refsnes") # 2 args Arbitrary Arguments, *args tuple of args def my_function(*kids): print("The youngest child i..
-
[Python tutorial] 13. Control flow, Loop, Iterator코딩/Python 2022. 12. 21. 17:15
While Loops i = 1 while i < 6: print(i) i += 1 break i = 1 while i < 6: print(i) if i == 3: break i += 1 continue i = 0 while i < 6: i += 1 if i == 3: continue print(i) else i = 1 while i < 6: print(i) i += 1 else: print("i is no longer less than 6") For Loop fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) Looping Through a String for x in "banana": print(x) break fruits = ["app..
-
[Python tutorial] 12. Control flow, If...else코딩/Python 2022. 12. 21. 17:14
if ... elif ... else a = 200 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b") # a is greater than b Short Hand If if a > b: print("a is greater than b") Short Hand If ... Else Ternary Operators or Conditional Expressions a = 330 b = 330 print("A") if a > b else print("=") if a == b else print("B") # multiful else and a = 200..
-
[Python tutorial] 11. Operators코딩/Python 2022. 12. 21. 17:14
연산자, Operators 산술 연산자, Arithmetic operators 지정 연산자, Assignment operators 비교 연산자, Comparison operators 논리 연산자, Logical operators 동일 연산자, Identity operators 자격 연산자, Membership operators 비트 연산자, Bitwise operators 산술 연산자, Arithmetic Operators print(10 + 5) 연산자 이름 예 + 더하기 x + y - 빼기 x - y * 곱하기 x * y / 나누기 x / y % 나머지 나누기 Modulus x % y ** 제곱 x ** y // 바닥나누기 x // y 지정 연산자, Assignment Operators 연산자 예 S..
-
[Python tutorial] 10. Data type - Dictionary코딩/Python 2022. 12. 21. 17:14
Dictionaries key:value pairs ordered changeable do not allow duplicates thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 # any data types } print(thisdict) print(thisdict["brand"]) {'brand': 'Ford', 'model': 'Mustang', 'year': 1964} Ford Access Dictionary Items x = thisdict["model"] print(x) # Mustang # get() x = thisdict.get("model") print(x) # Mustang # Get Keys: keys() x = thisd..
-
[Python tutorial] 9. Data type - Sets코딩/Python 2022. 12. 21. 17:14
Sets unordered**(unindexed) unchangeable(possible to remove & add) do not allow duplicate values thisset = {"apple", "banana", "cherry"} # any data types set1 = {"apple", "banana", "cherry"} set2 = {1, 5, 7, 9, 3} set3 = {True, False, False} set4 = {"abc", 34, True, 40, "male"} thisset = {"apple", "banana", "cherry", "apple"} print(thisset) # {'cherry', 'banana', 'apple'} Constructor: set(()) th..
-
[Python tutorial] 8. Data type - Tuple코딩/Python 2022. 12. 21. 17:13
Tuples ordered (indexed) unchangeable allow duplicate values thistuple = ("apple", "banana", "cherry", "apple", "cherry") # allow duplicate values # Data Types: any data types tuple1 = ("apple", "banana", "cherry") tuple2 = (1, 5, 7, 9, 3) tuple3 = (True, False, False) tuple4 = ("abc", 34, True, 40, "male") Create Tuple With One Item: (...,) thistuple = ("apple",) thistuple = ("apple") # NOT a t..