Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KimMinSeob
Python
Commits
2fadb1c4
Commit
2fadb1c4
authored
6 years ago
by
KimMinSeob
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
d45953ca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
문자열연습.py
+107
-0
107 additions, 0 deletions
문자열연습.py
with
107 additions
and
0 deletions
문자열연습.py
0 → 100644
+
107
−
0
View file @
2fadb1c4
Python
3.7
.
1
(
v3
.
7.1
:
260
ec2c36a
,
Oct
20
2018
,
03
:
13
:
28
)
[
Clang
6.0
(
clang
-
600.0
.
57
)]
on
darwin
Type
"
help
"
,
"
copyright
"
,
"
credits
"
or
"
license()
"
for
more
information
.
>>>
#문자열
>>>
#pithon 이라는 문자열을 python으로 바꾸려면 어떡해야할까??
>>>
>>>
a
=
'
pithon
'
>>>
a
[
1
]
'
i
'
>>>
a
[
1
]
=
'
y
'
Traceback
(
most
recent
call
last
):
File
"
<pyshell#5>
"
,
line
1
,
in
<
module
>
a
[
1
]
=
'
y
'
TypeError
:
'
str
'
object
does
not
support
item
assignment
>>>
#문자열이나 튜플은 그 요소를 변경할 수 없다. 따라서 슬라이싱을 이용하여 바꿔줘야한다.
>>>
a
[:
1
}
SyntaxError
:
invalid
syntax
>>>
a
[:
1
]
'
p
'
>>>
a
[
2
:]
'
thon
'
>>>
a
[:
1
]
+
'
y
'
+
a
[
2
:]
'
python
'
>>>
#문자열 포맷팅
>>>
"
I eat %d apples.
"
.
%
3
SyntaxError
:
invalid
syntax
>>>
"
i eat %d apples.
"
%
3
'
i eat 3 apples.
'
>>>
"
i eat %s apples.
"
%
"
three
"
'
i eat three apples.
'
>>>
#문자열 관련 함수들
>>>
a
=
"
hobby
"
>>>
a
.
count
(
a
)
1
>>>
a
.
count
(
"
a
"
)
0
>>>
a
.
count
(
"
b
"
)
2
>>>
a
=
"
python is the best choice
"
>>>
a
.
find
(
'
o
'
)
4
>>>
a
.
find
(
'
i
'
)
7
>>>
#find는 글자가 가장 처음나온 위치를 알려준다.
>>>
a
.
find
(
'
z
'
)
-
1
>>>
a
.
index
(
'
z
'
)
Traceback
(
most
recent
call
last
):
File
"
<pyshell#25>
"
,
line
1
,
in
<
module
>
a
.
index
(
'
z
'
)
ValueError
:
substring
not
found
>>>
a
=
'
,
'
>>>
a
.
join
(
'
abcd
'
)
'
a,b,c,d
'
>>>
'
,
'
.
join
(
'
abvcd
'
)
'
a,b,v,c,d
'
>>>
a
=
'
hi
'
>>>
a
.
upper
()
'
HI
'
>>>
a
'
hi
'
>>>
a
=
'
HI
'
>>>
a
.
lower
()
'
hi
'
>>>
a
'
HI
'
>>>
a
=
'
life is too short
'
>>>
a
.
replace
(
'
life
'
,
'
your leg
'
)
'
your leg is too short
'
>>>
print
(
"
jump to python
"
)
jump
to
python
>>>
print
(
'''
life is too short
you need python
'''
)
life
is
too
short
you
need
python
>>>
print
(
'
/t/t/t/t/t/tPYTHON
'
)
/
t
/
t
/
t
/
t
/
t
/
tPYTHON
>>>
print
(
/
t
/
t
/
t
/
t
/
t
/
t
'
python
'
)
SyntaxError
:
invalid
syntax
>>>
print
(
'
\t\t\t\t\t\t
Python
'
)
Python
>>>
h
=
'
881120-1068234
'
>>>
a
=
h
[:
6
]
>>>
b
=
h
[
7
:]
>>>
a
'
881120
'
>>>
b
'
1068234
'
>>>
s
=
'
1980M1120
'
>>>
s
[
0
]
=
M
Traceback
(
most
recent
call
last
):
File
"
<pyshell#49>
"
,
line
1
,
in
<
module
>
s
[
0
]
=
M
NameError
:
name
'
M
'
is
not
defined
>>>
print
(
'
M
'
+
s
[
0
:
4
]
+
s
[
5
:])
M19801120
>>>
a
=
'
life is too short, you need python
'
>>>
a
.
index
(
'
short
'
)
12
>>>
a
=
'
a:b:c:d
'
>>>
a
.
replace
(
'
:
'
,
"
#
'
)
SyntaxError: EOL while scanning string literal
>>>
a
.
replace
(
"
:
"
,
"
#
"
)
'
a#b#c#d
'
>>>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment