코딩
-
[Python/Module] RegEx코딩/Python 2022. 12. 22. 13:58
RegEx Regular Expression search pattern import re txt = "The rain in Spain" a = re.search("^The.*Spain$", txt) b = re.findall("ai", txt) RegEx Functions Function Description findall Returns a list containing all matches search Returns a Match object if there is a match anywhere in the string split Returns a list where the string has been split at each match sub Replaces one or many matches with ..
-
[Python/Module] JSON코딩/Python 2022. 12. 22. 13:58
JSON syntax for storing and exchanging data text, JavaScript object notation import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: print(y["age"]) Parse JSON - Convert from JSON to Python: json.loads() result: dictionary Convert from Python to JSON: json.dumps() import json # a Python object (dict): x = { "n..
-
[Python tutorial] 27. Exception코딩/Python 2022. 12. 21. 17:32
Exception Description ArithmeticError Raised when an error occurs in numeric calculations AssertionError Raised when an assert statement fails AttributeError Raised when attribute reference or assignment fails Exception Base class for all exceptions EOFError Raised when the input() method hits an "end of file" condition (EOF) FloatingPointError Raised when a floating point calculation fails Gene..
-
[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] 25. File Methods코딩/Python 2022. 12. 21. 17:30
file.close() Closes the file f = open("demofile.txt", "r") print(f.read()) f.close() file.fileno() Returns a number that represents the stream, from the operating system's perspective f = open("demofile.txt", "r") print(f.fileno()) file.flush() Flushes the internal buffer f = open("myfile.txt", "a") f.write("Now the file has one more line!") f.flush() f.write("...and another one!") file.isatty()..
-
[Python tutorial] 24. Set Methods코딩/Python 2022. 12. 21. 17:29
set.add(elmnt) Adds an element to the set fruits = {"apple", "banana", "cherry"} fruits.add("orange") set.clear() Removes all the elements from the set fruits = {"apple", "banana", "cherry"} fruits.clear() set.copy() Returns a copy of the set fruits = {"apple", "banana", "cherry"} x = fruits.copy() set.difference(set) Returns a set containing the difference between two or more sets x = {"apple",..