🐍 파이썬/파이썬 기본 문법
-
[Function] 함수란🐍 파이썬/파이썬 기본 문법 2022. 7. 18. 08:17
•A function is a namedset of instructions that performs a specific task. •A function can take one or more parameters (arguments) and returnsa value. •First mechanism for abstraction and decomposition •Advantage of using function : - Facilitates code reuse - Helps avoiding repetitive code - Hides implementation details - Makes testing easier parameters : - You can specify a default valuefor one o..
-
working with file🐍 파이썬/파이썬 기본 문법 2022. 7. 17. 07:39
create file # opening a file in write mode will either create a new file (if the file does not exist) # or overwrite an existing one f = open('test.txt', 'w') read file f = open('test.txt', 'r') contents = f.read() # read the entire file content print(contents) contents = f.read(10) # read only the first 10 characters of the file print(contents) line = f.readline() # read first line of the file ..
-
[string] 문자열 자주 쓰이는 문법 정리🐍 파이썬/파이썬 기본 문법 2022. 7. 17. 06:42
String indexing String formatting String method 1.대소문자 변환 .upper(), .lower() 메소드 (비파괴적 함수) a = "hello" a.upper() 2. 공백제거 .strip(), lstrip(), rstrip() a = " hello " a.strip() 3.구성 # moethods result boolean s = "some string..." s.startswith("some") # Bool: True s.endswith("!") # Bool: False "xxx" in s # Bool: False "1".isdigit() # Bool: True "e".isupper () # Bool: False "r".islower () # Bool: True..