본문 바로가기
Service/Coding

Google Python Automation Certification - Week 5

by 포항돼지 2022. 2. 5.

OOP Introduction

Object Oriented Programming

Classes and objects(instance)

class apple

   instance

 

 

 

class(attribute) apple

 

 

 

cut method(function)
eat method
file을 예로, 이러이러한 attribute 이 있고 이것들을 

Copy, Delete 뭐이런 거 하는거를 method, function이라고 함

dir("") 치면 뭐 쓸수있는지 다 나옴

help("") 치면 class help document 나옴

 

 

 

class Apple:
    pass
    color = ""
    flavor = ""

jonagold = Apple()

jonagold.color = "red"
jonagold.flavor = "sweet"

print(jonagold.color.upper())
print(jonagold.flavor.lower())

golden = Apple()
golden.color = "gold"
golden.flavor = "sower"

print(golden.color.upper())
print(golden.flavor.lower())

이런식으로 class만들어서 각각의 객체로 계속 찍어낼수 있음

 

class Flower:
  color = ''

rose = Flower()
rose.color = "red"

violet = Flower()
violet.color = "violet"

this_pun_is_for_you = "fuck you"

print("Roses are {},".format(rose.color))
print("violets are {},".format(violet.color))
print(this_pun_is_for_you) 

 

 

Python modules are separate files that contain classes, functions, and other data that allow us to import and make use of these methods and classes in our own code. Python comes with a lot of modules out of the box. These modules are referred to as the Python Standard Library. You can make use of these modules by using the import keyword, followed by the module name. For example, we'll import the random module, and then call the randint function within this module:

 

>>> import random
>>> random.randint(1,10)
8
>>> random.randint(1,10)
7
>>> random.randint(1,10)
1

 

이런식으로 모듈 임포트 해서, 미리 만들어놓은 라이브러리 쉽게 사용 가능

 

 

 

 

 

 

 

 

convince = 납득시키다 , 설득하다