Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.

1938 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a='hello melon'
>>> print(a[6:9])
mel
>>> print(a[-1:]
...
... print(a[-3:])
File "<stdin>", line 1
print(a[-1:]
^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> print(a[-5:-3])
me
>>> b['hey',"what's",'up']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> b=['hey',"what's",'up']
>>> print(b)
['hey', "what's", 'up']
>>> print(a[1])
e
>>> print(b[1])
what's
>>> ticker="fne-snem"
>>> new_ticker=ticker.upper()
>>> new_ticker
'FNE-SNEM'
>>> hello_ticker=ticker.lower()
>>> hello_ticker
'fne-snem'
>>> date="2024-04-23"
>>> date.split('-')
['2024', '04', '23']
>>> name="KAKAO"
>>> new_name='T'+name[1:]
>>> new_name
'TAKAO'
>>> new_name2=name.repace('K','T',1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'repace'. Did you mean: 'replace'?
>>> new_name2=name.replace('K','T',1)
>>> new_name2
'TAKAO'
>>> new_name2=new_name.replace('K','T',1)
>>> new_name2
'TATAO'
>>> len(date)
10
>>> code=" 12344 "
>>> code=code.strip()
>>> code
'12344'
>>> close="664,242,142"
>>> close.replace(",","")
'664242142'
>>> close=664242142
>>> format(close,",d")
'664,242,142'
>>> a="2024/04/23"
>>> a.replace("/","-",2)
'2024-04-23'
>>> b="Daum KAKAO"
>>> f=b[:4]
>>> f
'Daum'
>>> year='123.12"
File "<stdin>", line 1
year='123.12"
^
SyntaxError: unterminated string literal (detected at line 1)
>>> year='21.321'
>>> int(float(year))
21
>>> int(year)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '21.321'
>>> float(year)
21.321
>>> year=2023
>>> str(year)+"-03-43"
'2023-03-43'
>>> year='123.453'
>>> int(float(year*3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '123.453123.453123.453'
>>> int(float(year)*3)
370
>>> 교통편=["자동차","지하철","비행기","자전거"]
>>> print(교통편[:3])
['자동차', '지하철', '비행기']
>>> print(교통편[2])
비행기
>>> x=(234,254,534,421)
>>> print(x)
(234, 254, 534, 421)
>>> print(type(x))
<class 'tuple'>
>>> print(x[:2])
(234, 254)
>>> x[0]=100
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> #왜냐하면 튜플은 수정이 불가능하기 때문이다
>>> data1=[10,20,30]
>>> data2=tuple(data1)
>>> print(type(data2))
<class 'tuple'>
>>> print(type(data1))
<class 'list'>
>>> d=('naver',10,1324,(2023,4,12)
... 종목, 수량, 현재가, 날짜 =d
File "<stdin>", line 1
d=('naver',10,1324,(2023,4,12)
^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> d=('naver',10,1234,(2023,4,12))
>>> 종목, 수량, 현재가, 날짜 =d
>>> print(수량)
10
>>> print(현재가)
1234
>>> v=[234235,234563,574563,975953]
>>> last_vol, *trailing_vol=vol
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'vol' is not defined
>>> ice={
... "mel":1800
... "org":1700
File "<stdin>", line 2
"mel":1800
^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> ice={
... "mel":1800
... "org":1700
File "<stdin>", line 2
"mel":1800
^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> ice={
... "mel":1800,
... "org":1600,
... "lim":1600
... }
>>> type(ice)
<class 'dict'>
>>> print(ice["org"])
1600
>>> #딕셔너리는 이렇게 인덱싱한다
>>> print(ice.get("lim"))
1600
>>> print(icee.get("apple"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'icee' is not defined. Did you mean: 'ice'?
>>> print(ice.get("manggo"))
None
>>> #딕셔너리 안에 없는 값을 get 함수로 정하면 NONE 이라 뜬다
>>> ice["mel"]=1700
>>> ice
{'mel': 1700, 'org': 1600, 'lim': 1600}
>>> #이렇게 수정된다
>>> del ice["lim"]
>>> ice.keys()
dict_keys(['mel', 'org'])
>>> ice.values()
dict_values([1700, 1600])
>>> apt={
... [101,102],
... [201,202],
... [301,302]
... }
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> apt=[
... [101,102],
... [201,202],
... [301,302]
... ]
>>> type(apt)
<class 'list'>
>>> print(apt[0])
[101, 102]
>>> print(apt[1][0])
201
>>> #2 차원 리스트(괄호가 2 개)에서 인덱싱은 이런식으로 할 수 있다
>>> v=[234211,545748,235780,547892]
>>> last_vol, *trailing_vol=v
>>> trailing_vol
[545748, 235780, 547892]
>>> 버킷.append("네이버")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '버킷' is not defined
>>> 버킷=[]
>>> 버킷.append("apple")
>>> 버킷
['apple']
>>>

You might also like