개발/Python
[기본 2]Python의 문자열함수, print, input
cozynow
2017. 12. 28. 00:12
Python의 문자열 다루기¶
In [4]:
import pandas as pd
#url = "http://cozy.ddns.net:3888/notebooks/PythonSchool/aTO0.csv"
#pd.read_csv(url, nrows=2)
raw_data ={
'Data':['A','1','2','3','4','5','6','7','8','9','0']
}
df = pd.DataFrame(raw_data )
df
Out[4]:
In [2]:
aTO0 = 'A1234567890'
#0 부터 시작하니 2인경우 2이 나온다.
print("aTO0[2] = {}".format(aTO0[2]))
#0부터 2-1 까지
print("aTO0[0:2] = {}".format(aTO0[0:2]))
#0부터 5-1까지
print("aTO0[:5] = {}".format(aTO0[:5]))
#젤 뒤가 -1 이므로 -2이면 뒤에서 앞으로 한자리 앞이 나옴
print("aTO0[-2] = {}".format(aTO0[-2]))
#2자리부터 끝까지 2칸씩 출력
print("aTO0[1::2] = {}".format(aTO0[1::2]))
#0부터 5-1까지 2칸씩
print("aTO0[:5:2] = {}".format(aTO0[:5:2]))
#9에서 3+1까지 -1칸씩
print("aTO0[9:3:-2] = {}".format(aTO0[9:3:-2]))
a = "hello"
b = 'world'
print(a +' '+ b)
x = '1 + 3 ='
y = 4
#숫자와 문자를 연산할 수 없다.
#print(x + y)
#이건 되어야 함????
print(x + str(y))
print("문자길이 len(a+b) = {}".format(len(a+b)))
In [22]:
name = 'akami'.title()
score = 99.999
#%10s는 10자에 문자열을 넣는다.
print("^%10s got ^%2.2f score."%(name, score))
input 함수¶
In [28]:
x = int(input("Enter your number : "))
print(x * 3)