str1=['a', 'b', 'c']
str1='#'.join(str1) # iterable이 와야함
print(str1)
# === 출력 === #
a#b#c
str1="/clean-img-arch-64-build/14169"
print('_'.join(str1.split('/')[-2:]))
# === 출력 ==== #
clean-img-arch-64-build_14169
string=''.join(<list>)
str( <list> )
하면 되지 않나?list
표현 그대로 출력된다.''.join(<list>)
로 변환하면된다!
line="hello"
print(len(line)) # 5 (idx는 0~4)
str1= \
'''
string1
string2
'''
=== 출력 ===
string1
string2
name = name.upper()
name = name.lower()
str.startswith(찾을 문자열 | tuple[][, start[, end]]) -> bool
str1="hello myname is mark"
print(str1.startswith("hello")) # True
str2="hellomyname is mark"
print(str2.startswith("hello")) # True
str3="hellomyname is mark"
print(str3.startswith("myname")) # False
search_tuple=("world", "hello")
print(str1.startswith(search_tuple)) # True
str1="abc"
print(str1.endswith('c'))
=== 출력 ===
True
str1 = "aBc".capitalize()
print(str1)
=== 출력 ===
Abc
str1 = "aBc dEFG".title()
print(str1)
=== 출력 ===
Abc Defg
str1 = " hello ".strip() # 디폴트 공백
str2 = "____hello____".strip('_') # '_' 양 끝에 자르기
print(str1)
print(str2)
=== 출력 ===
hello
hello
str1 = "abc"
str1 = str1.replace('a', 'b') # replace(x, y) then, x to y
print(str1)
=== 출력 ===
bbc
tuple
형태 출력str1 = "pllpokko@alumni.kaist.ac.kr"
str1 = str1.partition('.')
print(str1)
=== 출력 ===
('pllpokko@alumni', '.', 'kaist.ac.kr')
tuple
형태 출력str1 = "123-456-789"
str1 = str1.rpartition('-')
print(str1)
=== 출력 ===
('123-456', '-', '789')
list
형태 출력str1 = "pllpokko@alumni.kaist.ac.kr"
str1 = str1.split('.')
print(str1)
=== 출력 ===
['pllpokko@alumni', 'kaist', 'ac', 'kr']
var, arg = line.split('=',1)
'\n'
기준으로 나눔cmd_output
print(cmd_output)
Package libpsl5 (0.21.0-r0) is installed on root and has the following files:
/home/dhyang/local_workspace/rootfs/usr/lib/libpsl.so.5
/home/dhyang/local_workspace/rootfs/usr/lib/libpsl.so.5.3.2
split('\n')
처리print(cmd_output.split('\n'))
['Package libpsl5 (0.21.0-r0) is installed on root and has the following files:', '/home/dhyang/local_workspace/rootfs/usr/lib/libpsl.so.5', '/home/dhyang/local_workspace/rootfs/usr/lib/libpsl.so.5.3.2', '']
strip().split('\n')
처리print(cmd_output.split('\n'))
['Package libpsl5 (0.21.0-r0) is installed on root and has the following files:', '/home/dhyang/local_workspace/rootfs/usr/lib/libpsl.so.5', '/home/dhyang/local_workspace/rootfs/usr/lib/libpsl.so.5.3.2']
list
형태 출력str1 = "pllpokko@alumni.kaist.ac.kr"
str1 = str1.rsplit('.')
print(str1)
=== 출력 ===
['pllpokko@alumni', 'kaist', 'ac', 'kr']
list
형태 출력str1 = \
'''
Life too short
you need python
'''
print(str1.splitlines())
=== 출력 ===
['','Life is too shrot', 'you need python']
str1=\
'''
HELLO
hello
'''
print(str1.count('hello'))
=== 출력 ===
1
str1='hello world!'
print(str1.find('w'))
=== 출력 ===
6
hello worl
----------
0123456789 배열식 idx 형태로 재서 리턴
str1='hello world!'
print(str1.find('ld!'))
=== 출력 ===
9
hello world!
------------
0123456789 찾은 문자열의 제일 앞 idx 리턴
str1='hello world!'
print(str1.find('ld!'))
=== 출력 ===
9
hello world!
------------
0123456789 찾은 문자열의 제일 앞 idx 리턴
removeprefix('대상')
: prefix 제거str1 = "lib32-starwars"
str1 = str1.removeprefix('lib32-')
# str1에 'lib32-' prefix가 없더라도 넘어감
print(str1)
# ==== 출력 ==== #
starwars
print('x'.isalnum()) # True
print('3'.isalnum()) # True
print('3.14'.isalnum()) # False '.'<-- 때문에 '.'는 알파멧 아님
print('3x'.isalnum()) # True
print('10'.isdecimal()) # True
print('0'.isdecimal()) # True
print('10.4'.isdecimal()) # False
print('10'.isdigit()) # True
print('0'.isdigit()) # True
print('10.4'.isdigit()) # False