초보개발자의 초보블로그
Hello World
728x90
300x250

Coding/Python 4

파이썬 리스트 원소 다양한 추가 방법

1. append() => 끝에 항목을 추가합니다. list = [1,2,3,4] list.attend(5) #결과=> list= [1,2,3,4,5] #배열의 끝에 5가 추가된것을 확인할수 있습니다! 2. extend() 또는 +(연산자) => 리스트를 결합합니다. list = [1,2,3,4] list.extend([5,6])#리스트를 extend #결과=> list = [1,2,3,4,5,6] #배열의 끝에 5와6이 추가된것을 확인할수 있습니다! list = [1,2,3,4] list = list+[5,6] #결과=> list = [1,2,3,4,5,6] #배열의 끝에 5와6이 추가된것을 확인할수 있습니다! 3. insert() => 지정된 인덱스(위치)에 원소를 삽입합니다. list = [1,2,..

Coding/Python 2022.03.03

Discord bot with Python #1

from discord.ext import commands bot = commands.Bot(command_prefix='!') @bot.event async def on_ready(): print('Logged in as') print(bot.user.name) # 토큰으로 로그인 된 bot 객체에서 discord.User 클래스를 가져온 뒤 name 프로퍼티를 출력 print(bot.user.id) # 위와 같은 클래스에서 id 프로퍼티 출력 print('------') @bot.command() async def ping(ctx): await ctx.send(f'pong! {round(round(bot.latency, 4)*1000)}ms') # 봇의 핑을 pong! 이라는 메세지와 함께 전송한다...

Coding/Python 2021.05.27

파이썬 정규식 기본(?)

import re # abcd, book, desk # ca?e # care, cafe, case, cave p = re.compile("ca.e") # . (ca.e): 하나의 문자를 의미 > care, cafe, case (O) | caffe (X) # ^ (^de) : 문자열의 시작 > desk, destination (O) | fade (X) # $ (se$) : 문자열의 끝 > case, base (O) | face (X) def print_match(m): if m: print("m.group():",m.group()) # 일치하는 문자열 반환 print("m.string:",m.string) # 입력받은 문자열 print("m.start():", m.start()) # 일치하는 문자열의 시작..

Coding/Python 2021.05.04
1
반응형
loading