Python
-
[Python tutorial] 20. String methods코딩/Python 2022. 12. 21. 17:18
string.capitalize() Converts the first character to upper case txt = "hello, and welcome to my world." x = txt.capitalize() print (x) string.casefold() Converts string into lower case txt = "Hello, And Welcome To My World!" x = txt.casefold() print(x) string.center(length, character) Returns a centered string txt = "banana" x = txt.center(20) print(x) string.count(value, start, end) Returns the ..
-
[Python tutorial] 19. Built-in Function코딩/Python 2022. 12. 21. 17:18
abs(n) Returns the absolute value of a number x = abs(-7.25) all(iterable) Returns True if all items in an iterable object are true mylist = [True, True, True] x = all(mylist) any(iterable) Returns True if any item in an iterable object is true mylist = [False, True, False] x = any(mylist) ascii(object) Returns a readable version of an object. Replaces none-ascii characters with escape character..
-
[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..