1_Python

2. 문자 제어 및 데이터 타입

느린개발자 2018. 10. 7. 19:46

1. 공부한 내용

 1) 문자의 표현과 문자열 제어

 2) 특수한 문자들에 대한 이해

 3) 문자와 숫자를 통한 데이터 타입 차이


2. 실습 내용 

 입력 코드

결과 

 설명

print("hello "+"world")

hello world

문자열의 + 역할

print("hello "*3)

hello hello hello 

문자열의 * 역할

print("hello" [1])

문자열의 []번째 문자를 출력 

print('python'.capitalize())

Python 

문자열의 첫 번째 문자를 대문자로 출력 (.capitalize()) 

print('python'.upper())

PYTHON

문자열 전부를 대문자로 출력 (.upper())

print('python'.__len__()) 또는 print(len('python'))

문자열의 갯수(길이)를 출력 (len()) 

print('python'.replace('hon', ' programming'))

pyt programming 

문자열 일부를 교체 (.replace()) 

print("har's \"programming\"")

har's "programming" 

' 또는 " 등 특수문자를 출력 (특수문자 앞에 \) 

print('\\')

\앞에 \를 입력하여 \만 출력하게 만듦 

print("har's \nprogramming")

har's

programming

문자열의 줄바꿈 (\n) 

print("har's \t\tcom") 

har's           com 

문자열의 탭 띄우기 (\t) 

print("\a")

알람음 울림 

알람음 울리게 함 (\a) 


3. 의미/중요한 부분

 1) "10+5" 와 10+5 의 결과는 다름. "" 가 들어감으로서 숫자를 문자로 인식하기 때문

 2) 문자 제어 코드 중 문자열 안에서 작동하는 코드는 "" 안에 있으며, 그 밖에는 ""를 벗어난 곳에 입력

ex) print("har's \ncom") , print('python'.replace('hon', ' pro'))

 3) 특수문자를 그 모양대로 출력하기 위해서는 특수문자 앞에 \를 붙혀야 함


4. 궁금점/감상

 1) 문자열 제어에 대한 대략적인 큰 흐름을 배운 느낌

 2) \n 등과 같은 코드는... 예전에 게임의 자바스크립트인가.. 노가다로 뭐 수정할 때 썼던 거 같은데.... 가물가물