본문 바로가기

코딩

[PYTHON] 생활코딩 복습

   : 1번째

   : 2번째

   : 3번째

 

######################################################true, false = 불리언

 

print('Hello ' + 'world')   

print('Hello ' * 3)

print('Hello' [0]) 

print('Hello' [1])

print('Hello' [2])

 

print('hello world'.capitalize())

print('hello world'.upper())

print('hello world'.__len__())

print(len('hello world'))

print('Hello world'.replace('world', 'programming'))

 

print("goorm's \"tutorial\"")

print("\\")

print("Hello\nworld")

print("Hello\t\tworld")

print("\a")

print('Hello\nworld')

 

######################################################################

 

in_str = input("입력해주세요.\n")

print(in_str.upper() + " World!")

 

in_str = input("아이디를 입력해주세요.\n")

real_egoing = "11"

real_k8805 = "ab"

if real_egoing == in_str:

print("Hello!, egoing")

elif real_k8805 == in_str:

print("Hello!, k8805")

else:

print("Who are you?")

 

in_str = input("아이디를 입력해주세요.\n")

real_egoing = "egoing"

real_k8805 = "k8805"

if real_egoing == in_str or real_k8805 == in_str:

print("Hello!")

else:

print("Who are you?")

 

input_id = input("아이디를 입력해주세요.\n")

input_pwd = input("비밀번호를 입력해주세요.\n")

real_id = "egoing"

real_pwd = "11"

if real_id == input_id and real_pwd == input_pwd:

print("Hello!")

else:

print("로그인에 실패했습니다")

 

###################################################container = list = array

 

print(type('egoing')) #<class 'str'>

name = 'egoing'

print(name) #egoing

print(type(['egoing', 'leezche', 'graphittie'])) #<class 'list'>

names = ['egoing', 'leezche', 'graphittie']

print(names)

print(names[2]) #graphittie

egoing = ['programmer', 'seoul', 25, False]

egoing[1] = 'busan'

print(egoing) #['programmer', 'busan', 25, False]

 

##########################################docs.python.org =>> 파이썬 설명서

 

al = ['A', 'B', 'C', 'D']

print(len(al)) # 4

al.append('E')

print(al) #['A', 'B', 'C', 'D', 'E']

del (al[0])

print(al) #['B', 'C', 'D', 'E']

 

members = ['egoing', 'leezche', 'graphittie']

for member in members:

print(member)

 

for item in range(5, 11):

print(item)

 

input_id = input("아이디를 입력해주세요.\n")

members = ['egoing', 'k8805', 'leezche']

for member in members:

if member == input_id:

print('Hello!, ' + member)

import sys

sys.exit()

print('Who are you?')

 

#####################################################################

 

input_id = input("아이디를 입력해주세요.\n")

 

def login(_id):

members = ['egoing', 'k8805', 'leezche']

for member in members:

if member == _id:

return True

return False

 

if login(input_id):

print('Hello, ' + input_id)

else:

print('Who are you?')

 

############################################################### module

 

from egoing import a as z

import k8805 as k

 

# . = "~~안에" /// ex : (auth.A()) = auth 모듈 안에 A 함수

 

input.A = input("이름을 입력해주세요\n")



def login(i):

names = ["철수", "영희"]

for i in names:

if input.A == i:

return True

return False



if login(input.A):

print("hello " + input.A)

else:

print("Who Are you?")

 

A = "asdpsdasd"

print(A.upper())

 

##################################################################계산기

 

input_A = input("값을 입력하세요\n")

input_B = input("값을 입력하세요\n")



def cal(input_A, input_B):

print("결과값은 다음과 같습니다.")

print("더하기값 : " + str(int(input_A) + int(input_B)))

print("곱하기값 : " + str(int(input_A) * int(input_B)))

print("나누기값 : " + str(int(input_A) / int(input_B)))

print("빼기값 : " + str(int(input_A) - int(input_B)))

return

 

###################################self는 필수적인 첫 번째 매개변수, v1, v2는 입력값

 

class Cal(object):

def __init__(self, v1, v2):  ## __init__이라는 생성자로 진입. 및 매개변수 입력

self.v1 = v1

self.v2 = v2

 

def add(self):

return self.v1 + self.v2

 

def subtract(self):

return self.v1 - self.v2

 

 

c1 = Cal(10, 10)

print(c1.add())

print(c1.subtract())

c2 = Cal(30, 20)

print(c2.add())

print(c2.subtract())

 

############################################################# get, set 메소드

 

class C(object):

def __init__(self, v):

self.value = v

def show(self):

print(self.value)

def getValue(self):

return self.value

def setValue(self, v):

self.value = v

c1 = C(10)

print(c1.getValue())

c1.setValue(20)

print(c1.getValue())

'코딩' 카테고리의 다른 글

[PYTHON] 파이썬 예제 뽀개기  (0) 2020.03.10
[PYTHON] 기본 함수  (0) 2020.03.10
[PYTHON] Beautiful soup  (0) 2020.03.09
[PYTHON] 용어 참고  (0) 2020.03.07
[HTML] 용어 참고  (0) 2020.03.07