jsup/avle code update - you don't have to write post everyday

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/jsup-avle-code-update-you-don-t-have-to-write-post-everyday Hello, this is @joviansummer, developer of @jsup and@avle voting service. Voting service code for @jsup and @avle has been updated. I had been considering this update for a while, and recently I could come up with detailed implementation plan which resulted in a relatively swift code revision. The new added feature is capability to give daily upvote to the first thing you write for the day(timezone GMT+9) regardless of post or comment/reply. Writing a post everyday can be challenging. In that case, you can write a reply to receive daily upvote because writing a reply everyday is much easier and also a good way to engage in your community. Writing a post everyday just to get an upvote can be very tedious and exhausting, and post itself could easily become low-quality. There may be people who enjoy writing a post everyday, but we can't ignore th...

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

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

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

[ENG] jsup 2.0 - make your upvote great again

[EN] STEEM-services: dapps/services webpage with sort and search functions