-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudy_string.py
More file actions
44 lines (44 loc) · 1.32 KB
/
study_string.py
File metadata and controls
44 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#주석 문자열 차이??
"""주석"""
"""문
자
열"""
#문자열 연산
print("hello" + " world")
print("Hello " * 3)
#인덱싱
str = "abcde"
print(len(str))
print(str[0] + " " + str[-0] + " " + str[-1])
#슬라이싱
print(str[0:4])
print(str[:4])
print(str[:])
print(str[1:])
print(str[1:-1])#-1포함 X->-2까지 포함
print(str[-2:-1])
#str[1] = 'a' [error]: string is immutable!!
#문자열 포멧
a=11;b=22;c=33;
print("여러 문자열 포멧 코드: %d %d %d" %(a, b, c))
print("문자열 포멧 %s %s %s" %(a, "fwfw", 1.2E2))#E/e '숫자' 로 지수 표현, 10^숫자
print("100%")
print("%d%%" %a)
print("%10s" %"hello")#오른쪽으로 정렬, 적어도 문자열 10칸되게 공백으로 채움
print("%10s" %"helloaaaaaa")#10칸 넘으면 그대로
print("%-10s"%"fwe")#왼쪽 정렬
print("%.4f"%1.2)#소숫점 아래 4자리 까지만 표현
print("%10.4f"%1234.5678)#소숫점 아래 4자리 까지만 표현, 적어도 10자리 이상(소숫점 포함)
#format 함수
print("{0} {1} {name} {a} {a}".format(a, "b", a=1, name=c))
print("{str:^5}".format(str="ab"))
print("{str:^5}".format(str="abcdef"))
print("{str:!<10}".format(str="hi"))
print("{float:07.1f}".format(float=1.234))
print("{{{val}}}".format(val=10))
#expression
ceta=10
alph=beta=ceta
print(f"{alph}")
print(f"{123456789:,}")
print("{0:,}".format(123456789))