[ENG] STEEM Security update - added power down alert

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/eng-steem-security-update-added-power-down-alert STEEM Security - receive STEEM alert messages via Discord Hello, this is @joviansummer(witness: @jswit). STEEM Security code has been revised. Previously, STEEM Security was sending alert message via discord for the following 3 kinds of operations: sending STEEM/SBD to another account changing SP delegation account update Now, power down operation has been added. If there is a power down operation, you will also receive alert message. Please check the original post of the above link for detailed information on how to use the service. Thank you for reading, and have a wonderful day! @joviansummer's STEEM projects @jswit witness: I'm running a STEEM witness node. I'd really appreciate it if you vote for my witness account @jswit. ( https://steemitwallet.com/~witnesses ) [ENG] Introducing @jswit witness project @jsup curation: [ENG] Int...

파이썬에서 문자열에 특정한 문자열이 포함되었는지 확인

by joviansummer
original STEEMIT post: https://steemit.com/blog/@joviansummer/3yclh3


문자열(str) 형식의 변수에 특정한 문자열이 포함되어 있는지 확인하려면 find()를 사용합니다. 아래와 같이 간단한 예시를 보겠습니다.

x = 'hello world'
x.find('hello')

위의 x.find('hello')는 문자열 x에 hello가 포함되어 있을 경우 해당 문자열이 시작되는 위치를 반환하게 됩니다. 이 예시에서 x의 맨 처음에 hello가 있으므로 반환되는 값은 0입니다. (위치는 0부터 셉니다.)

변수에 할당하지 않고 문자열 자체에 대해서도 find()를 사용할 수 있습니다.

# 첫번째 등장하는 o의 위치 찾기 
'hello world'.find('o')

만약 일치하는 문자열이 없을 경우에는 -1을 반환합니다.

x.find('abcd')

위의 예시처럼 문자열 "abcd"를 찾는다면 "hello world"에는 포함되어 있지 않으므로 -1을 반환할 것입니다.

따라서, 반환되는 값이 0 이상이면 문자열이 포함되어 있는 것이라고 판단할 수 있습니다. if 조건문으로 아래와 같이 문자열 포함 여부를 확인할 수 있습니다.

x = 'hello world'
if x.find('hello') >= 0:
  print('x에 hello가 포함되어 있습니다. 위치는 ', x.find('hello'), '입니다.')
else:
  print('x에 hello가 포함되어 있지 않습니다.')

예시를 하나 더 보겠습니다.

x = 'hello world'
y = 'abcd'
if x.find(y) == -1:
  print('x에 ', y, '가 포함되어 있지 않습니다.')

Comments

Popular posts from this blog

[ENG] jsup 2.0 - make your upvote great again

jsup/avle 보팅 코드 갱신 - 1일1포스팅 강박에서 벗어나기

Nuitka - 파이썬 스크립트를 바이너리 실행 파일로 변환