문자열메서드
s="hello"
print(s.capitalize())
print(s.upper())
print(s.replace('l','ell'))
print(' world '.strip())
print(s.split())
print(s)
Hello
HELLO
heellello
world
['hello']
hello
Print
for i in 'abcd':
print(i,end="")
print("\n",1,2,3,4,sep='분리')
abcd
분리1분리2분리3분리4
dictionary
a={'a':123,'b':456,'c':789}
for key,value in a.items():
print(key,value)
print(a.items())
a 123
b 456
c 789
dict_items([('a', 123), ('b', 456), ('c', 789)])
ZIP
num=[1,2,3]
letter=['a','b']
for x,y in zip(num,letter):
print(x,y)
print(zip(num,letter))
1 a
2 b
전역변수
name='steve'
def glob(x):
global name
name=x
glob('jack')
print(name)
jack
함수의 Default값
def getSum(a,b,c=20):
res=a+b+c
return res
print(getSum(1,2))
print(getSum(1,2,3))
23
6
Map
def getName(name):
return name+' Captin'
list(map(getName,['a','b','c']))
['a Captin', 'b Captin', 'c Captin']
클래스변수와 인스턴스
class Account:
num_accounts=0
def __init__(self,name):
self.name=name
Account.num_accounts+=1
def __del__(self):
Account.num_accounts-=1
def mol(self,num):
Account.num_accounts=30
kim=Account("kim")
lee=Account('lee')
print(Account.num_accounts)
print(lee.__dict__)
lee.mol(20)
print(Account.num_accounts)
2
{'name': 'lee'}
30
오버라이딩
class P:
def printName(self,):
print('P class print')
class S(P):
def printName(self,):
super().printName()
print('S class print')
s1=S();
s1.printName()
P class print
S class print
import
import apple.ipad.draw->apple.ipad.draw.drawPicture()
from game.ipad import draw->draw.drawPicture()
from game.ipad.draw import 함수,변수,모듈->drawPicture()