본문 바로가기
<개인공부> - IT/[Python]

Python 소문자 변경하는 함수만들기

by Aggies '19 2018. 8. 17.
반응형



def lowercase(string):
lowercaseStr = ""
for index in range(len(string)):

# Condition : uppercase letter, replace uppercase letter to lowercase letter
if(65 <= ord(string[index]) and ord(string[index]) <= 90):
asciiIndex = ord(string[index]) + 32
lowercaseStr += chr(asciiIndex)
# Condition : lowercase letter, Just adds on original letter
else:
lowercaseStr += string[index]
return lowercaseStr

print (lowercase("Hi Cassie! COLLEGE station weather is REALLY HoT"))



* ord function

  : It is a inbuilt function return an integer representing the Unicode code


Examples:

Input : a
Output : 97

Reference site : https://www.geeksforgeeks.org/ord-function-python/


* chr function

  : It is a inbuilt function that converts ASCII-based number to character


Syntax:

chr(num)
num : integer value

Reference site : https://www.geeksforgeeks.org/chr-in-python/

반응형