반응형

 

문자를 출력하다 보면 큰따옴표, 따옴표 출력이 필요할 때가 있습니다.

 

print로 간단하게 출력하는 방법을 보여드리겠습니다.

 

따옴표 및 큰따옴표 출력하기

 

왼쪽) 입력 / 오른쪽) 출력

a = "This is the python code."
#출력 : This is the python code.
b = "This is the 'python' code."
#출력 : This is the 'python' code.
c = 'This is the "python" code.'
#출력 : This is the "python" code.
d = '''This is the 'python' code.'''
#출력 : This is the 'python' code.
e = '''This is the "python" code.'''
#출력 : This is the "python" code.
f = """This is the 'python' code."""
#출력 : This is the 'python' code.
g = """This is the "python" code."""
#출력 : This is the "python" code.

 

큰따옴표로 전체를 묶고 안에 따옴표를 이용해 출력할 수 있으며, 반대로 따옴표로 전체를 묶고 안에 큰따옴표를 이용해서 출력할 수도 있습니다.

 

반응형

 

여러 줄 출력하기

 

왼쪽) 입력 / 오른쪽) 출력

h = "This is \
the python \
code."
# 출력 : This is the python code.

i = '''This is
the 'python'
code.'''
#출력 : This is
#       the 'python'
#       code.

 

역슬러쉬를 이용해서 문장이 이어지도록 연결할 수 있으며, 따옴표 3개를 이용해 여러 줄을 한꺼번에 연결해서 출력할 수도 있다.

 

반응형
반응형
반응형

기존 파이썬을 이용하면 라이브러리를 하나하나 설치해야 하지만

아나콘다를 통해서 여러 패키지(NumPy, SymPy, Matplotlib, 등)를 포함하여 제공한다. 

 

https://www.anaconda.com/

 

Anaconda | The World's Most Popular Data Science Platform

Anaconda is the birthplace of Python data science. We are a movement of data scientists, data-driven enterprises, and open source communities.

www.anaconda.com

 

아나콘다 홈페이지

 

설치 과정

 

 

 

Jupyter Notebook

 

 

Anaconda Prompt

 

python --version

Spyder

 

반응형
반응형
반응형

대문자 나 소문자 알파벳 리스트가 필요할때 일일이 노가다로 넣을수도 있지만 편리한 함수가 있다.

 

준비 : string 패키지를 import 해줘야 한다.

 

대,소문자 출력

 

string.ascii_lowercase : 소문자 + 대문자 순으로 출력한다

string.ascii_uppercase : 대문자 출력

string.ascii_lowercase : 소문자 출력

 

 

 

배열로 입력

 

※ 변수 = list(string.ascii_lowercase)

리스트로 변수에 간단히 입력해도 된다.

반응형
반응형
1. 문자 소문자로 변환 출력중


built-in method lower of str object at 0x037D85C0

 

문자열이 제대로 출력이 되지않아 확인해보니

 

....

 

()빠짐..

 

2. 리스트 문자열을 int로

 

<map object at 0x04CA80B0>

테스트 파이썬 버전은 3.0

 

3. 들여쓰기 문제

Inconsistent use of tabs and spaces in indentation

 

전혀 문제 될게 없어 보인다.

 

앞부분 탭 + 스페이스, 탭 + 탭 혼종으로 섞여 있어서 그렇다.

정리해서 통일감 있게 정리하면 끝.

반응형
반응형

마우스 키보드 제어를 위해 라이브러리 설치

 

pip install mouse

pip install keyboard

 

 

1) 마우스 위치 좌표 출력

- 소스코드)

1
2
3
4
5
6
7
8
9
import mouse as mo
import time
def mo_posi():
    while True:
        print(mo.get_position())
        time.sleep(1)
 
if __name__ == "__main__":
    mo_posi()
cs

 

- 실행결과)

그림 1) 실행결과 값

 

 실행 후 자동으로 1초당 마우스 좌표를 출력해 준다.

 

 

 

2) 키보드로 좌표 시작 중지 설정

- 소스코드)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import mouse as mo
import keyboard as key
import time
 
def mo_posi():
    loop =False
    while True:
        if key.is_pressed('F2'== True:
            loop = True
        if key.is_pressed('F3'== True:
            loop = False
 
        if loop == True:
            print(mo.get_position())
            time.sleep(0.5)
            
if __name__ == "__main__":
    mo_posi()
cs

 

 

실행 결과는 그림 1)과 똑같으며 F2 누를 시 마우스 좌표를 0.5초마다 출력 F3 누르면 정지

 

 

 

 

3) 좌표 원하는 회수 입력

 

 -)소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import mouse as mo
import keyboard as key
 
def locSave(cnt):
    print('mouse move and press f2')
    returnList = []
    wcnt = 0
    state = False
    while True:
        val = key.is_pressed('F2')
        if state != val:
            if val == True:
                wcnt += 1
                returnList.append(mo.get_position())
                print('catch')
            state = val
        if wcnt >= cnt:
            return returnList
 
        
if __name__ == "__main__":
    count = int(input("Count :"))
    print(locSave(count))
cs

 

 

-) 실행결과

그림 2)

처음 희망하는 좌표 개수를 입력하고 F2키를 통해 마우스를 원하는 위치에서 눌러 입력

 

 

 

반응형
반응형

- 파이썬 openpyxl 설치

 

* 아래 다운로드 주소 openpyxl-3.0.4.tar.gz

 

pypi.org/project/openpyxl/#files

 

openpyxl

A Python library to read/write Excel 2010 xlsx/xlsm files

pypi.org

 

 

 

그림 1

 

 

명령 프롬프트에서 pip install openpyxl-3.0.4 쳐보니 에러가 뜬다

 

Could not find a version that satisfies the requirement openpyxl-3.0.4 (from versions: )
No matching distribution found for openpyxl-3.0.4

위 두줄은 openpuxl-3.0.4를 못 찾는 거 같고


You are using pip version 19.0.3, however version 20.2b1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

위 두줄은 pip 버전을 업데이트 해달라는 뜻으로 추정된다.

 

 

그림 2

 

 

파이썬 설치경로에서 python -m pip install --upgrade pip 명령어를 치니 업데이트가 된다.

 

 

 

그림 3

 

 

업데이트는 됬으나 openpuxl-3.0.4를 못 찾는 거 같아 보인다.

 

 

 

그림 4

 

깔끔하게 설치 되었습니다

 

반응형
반응형

 

파이썬 스택 자료구조 입니다.

 

 

소스코드.txt
0.00MB

 

소스코드 이미지

 

 

 

 

실행화면

 

 

부족한 부분이나 추가해 주었으면 하는 것이 있으면

댓글 달아주십시오.

반응형

+ Recent posts