Python
-
[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] 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",..
-
[Python tutorial] 23. Tuple Methods코딩/Python 2022. 12. 21. 17:28
tuple.count(value) Returns the number of times a specified value occurs in a tuple thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) x = thistuple.count(5) tuple.index(value) Searches the tuple for a specified value and returns the position of where it was found thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) x = thistuple.index(8)
-
[Python tutorial] 21. List/Array methods코딩/Python 2022. 12. 21. 17:18
list.append(elmnt) Adds an element at the end of the list fruits = ['apple', 'banana', 'cherry'] fruits.append("orange") list.clear() Removes all the elements from the list fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.clear() list.copy() Returns a copy of the list fruits = ['apple', 'banana', 'cherry', 'orange'] x = fruits.copy() list.count(value) Returns the number of elements with t..