coding
-
[Python/Module] Datetime코딩/Python 2022. 12. 21. 17:31
Python Dates 날짜, 시간은 파이썬에 포함되지 않음 'datetime' 모듈 사용 import datetime x = datetime.datetime.now() y = datetime.datetime(2020, 5, 17) # object from datetime() class z = datetime.datetime(2018, 6, 1) print(x) # 2022-12-16 15:33:49.473356 print(x.year) # 2022 print(x.strftime("%A")) # Friday print(y) # 2020-05-17 00:00:00 print(x.strftime("%B")) # June Date Output 2022-12-16 15:30:04.284752: year, mon..
-
[Python tutorial] 16. Classes, Objects and Inheritance코딩/Python 2022. 12. 21. 17:16
Classes and Objects OOP(Object Oriented Programming)언어: 속성과 메서드(명령, 함수)를 가지는 객체 클래스: 객체를 생성하기 위한 기본청사진 객체: 실제 사용되는 대상 Create a Class: class class MyClass: # create a class 'MyClass' x = 5 # property p1 = MyClass() # create a object 'p1' print(MyClass) # print(p1.x) # 5 class Person: def __init__(self, name, age): self.name = name self.age = age def __str__(self): return f"{self.name}({self.age})..
-
[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..