Skip to content
Snippets Groups Projects
Commit 2fadb1c4 authored by KimMinSeob's avatar KimMinSeob
Browse files

Upload New File

parent d45953ca
Branches
No related tags found
No related merge requests found
Python 3.7.1 (v3.7.1:260ec2c36a, 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\tPython')
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'
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment