Skip to content
Snippets Groups Projects
Commit 80807238 authored by 장범진's avatar 장범진
Browse files

Upload New File

parent 8637e5a3
No related branches found
No related tags found
No related merge requests found
python.py 0 → 100644
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> a=['aaa','bbb','ccc']
>>> a
['aaa', 'bbb', 'ccc']
>>> a[0]
'aaa'
>>> a[0:2]
['aaa', 'bbb']
>>> a[0:3]
['aaa', 'bbb', 'ccc']
>>> a[2:]
['ccc']
>>> a[1:]
['bbb', 'ccc']
>>> a[:2]
['aaa', 'bbb']
>>> a[:3]
['aaa', 'bbb', 'ccc']
>>> a.append(dddd)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
a.append(dddd)
NameError: name 'dddd' is not defined
>>> a.append('ddd')
>>> a
['aaa', 'bbb', 'ccc', 'ddd']
>>> a.extend('[eee','fff','ggg'])
SyntaxError: invalid syntax
>>> a.extend(['eee','fff','ggg'])
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg']
>>> a.insert(1,'www')
>>> a
['aaa', 'www', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg']
>>> a.remove('www')
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg']
>>> a.pop()
'ggg'
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']
>>> a.pop(2)
'ccc'
>>> a
['aaa', 'bbb', 'ddd', 'eee', 'fff']
>>> a.insert(2,'ccc')
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']
>>> count(a)
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
count(a)
NameError: name 'count' is not defined
>>> count('a')
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
count('a')
NameError: name 'count' is not defined
>>> a,conut('a')
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
a,conut('a')
NameError: name 'conut' is not defined
>>> a.count(a)
0
>>> a.count(aaa)
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
a.count(aaa)
NameError: name 'aaa' is not defined
>>> a.count('aaa')
1
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']
>>> b=[5,3,2,4,1]
>>> b.sort
<built-in method sort of list object at 0x0000027B97528588>
>>> b
[5, 3, 2, 4, 1]
>>> b.sort
<built-in method sort of list object at 0x0000027B97528588>
>>> b
[5, 3, 2, 4, 1]
>>> b.sort(reverse =True)
>>> b
[5, 4, 3, 2, 1]
>>> b.sort(reverse = False)
>>> b
[1, 2, 3, 4, 5]
>>> c=[3,4,5,1,2]
>>> c.sort
<built-in method sort of list object at 0x0000027B97528748>
>>> c
[3, 4, 5, 1, 2]
>>> b.sort()
>>> b
[1, 2, 3, 4, 5]
>>> c.sort
<built-in method sort of list object at 0x0000027B97528748>
>>> c.sort()
>>> c
[1, 2, 3, 4, 5]
>>> b
[1, 2, 3, 4, 5]
>>> c.sort(reverse =True)
>>> c
[5, 4, 3, 2, 1]
>>> a.reverse()
>>> a
['fff', 'eee', 'ddd', 'ccc', 'bbb', 'aaa']
>>> a
['fff', 'eee', 'ddd', 'ccc', 'bbb', 'aaa']
>>> a.reverse(False)
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
a.reverse(False)
TypeError: reverse() takes no arguments (1 given)
>>> a.reverse
<built-in method reverse of list object at 0x0000027B9750CF48>
>>> a.reverse()
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']
>>>
>>> a
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']
a
>>>
>>> c
[5, 4, 3, 2, 1]
>>> b
[1, 2, 3, 4, 5]
>>> type(a)
<class 'list'>
>>> type(b)
<class 'list'>
>>> type(c)
<class 'list'>
>>> a=(1,2,3)
>>> type(a)
<class 'tuple'>
>>> a
(1, 2, 3)
>>> a=1,2,3,4
>>> a
(1, 2, 3, 4)
>>> type(a)
<class 'tuple'>
>>> a=(1,)
>>> a
(1,)
>>> b=1.
>>> b
1.0
>>> b=1,
>>> b
(1,)
>>> type(b)
<class 'tuple'>
>>> c=(d)
Traceback (most recent call last):
File "<pyshell#81>", line 1, in <module>
c=(d)
NameError: name 'd' is not defined
>>> c=(1)
>>> type(1)
<class 'int'>
>>> a=1,2,3,4,5,6
>>> a[:3]
(1, 2, 3)
>>> a[4:6]
(5, 6)
>>> a=1,2,3
>>> b=4,5,6
>>> c=a+b
>>> a
(1, 2, 3)
>>> b
(4, 5, 6)
>>> c
(1, 2, 3, 4, 5, 6)
>>> a.append(4)
Traceback (most recent call last):
File "<pyshell#93>", line 1, in <module>
a.append(4)
AttributeError: 'tuple' object has no attribute 'append'
>>> a(0)
Traceback (most recent call last):
File "<pyshell#94>", line 1, in <module>
a(0)
TypeError: 'tuple' object is not callable
>>> a
(1, 2, 3)
>>> a[0]
1
>>> a[1]
2
>>> a[3]
Traceback (most recent call last):
File "<pyshell#98>", line 1, in <module>
a[3]
IndexError: tuple index out of range
>>> a[2]
3
>>> a[0]=7
Traceback (most recent call last):
File "<pyshell#100>", line 1, in <module>
a[0]=7
TypeError: 'tuple' object does not support item assignment
>>> len(a)
3
>>> 1,2,3 =b
SyntaxError: can't assign to literal
>>> one,two,three = a
>>> a
(1, 2, 3)
>>> one
1
>>> two
2
>>> three
3
>>> 3,2,1, =a
SyntaxError: can't assign to literal
>>> a,b,c=b
>>> a,b,c=d
Traceback (most recent call last):
File "<pyshell#110>", line 1, in <module>
a,b,c=d
NameError: name 'd' is not defined
>>> b
5
>>> a
4
>>> b
5
>>> c
6
>>> a=1,2,3
>>> one,two,three =a
>>> one
1
>>> two
2
>>> three
3
>>> city,latitude,longitude = a
>>> a="seoul",37.541, 126.986
>>> a
('seoul', 37.541, 126.986)
>>> seoul
Traceback (most recent call last):
File "<pyshell#123>", line 1, in <module>
seoul
NameError: name 'seoul' is not defined
>>> city
1
>>> city,latitude,longitude =a
>>> city
'seoul'
>>> latitude
37.541
>>> longitude
126.986
>>> a.count(s)
Traceback (most recent call last):
File "<pyshell#129>", line 1, in <module>
a.count(s)
NameError: name 's' is not defined
>>> a.count('s')
0
>>> a.count(1)
0
>>> a
('seoul', 37.541, 126.986)
>>> a.count(37.541)
1
>>> a.count(37.54)
0
>>> b13
Traceback (most recent call last):
File "<pyshell#135>", line 1, in <module>
b13
NameError: name 'b13' is not defined
>>> a13
Traceback (most recent call last):
File "<pyshell#136>", line 1, in <module>
a13
NameError: name 'a13' is not defined
>>> 13a
SyntaxError: invalid syntax
>>> dic{}
SyntaxError: invalid syntax
>>> dic={}
>>> dic['파이썬']
Traceback (most recent call last):
File "<pyshell#140>", line 1, in <module>
dic['파이썬']
KeyError: '파이썬'
>>> dic['파이썬'] = 'www.python.org'
>>> dic["마이크로소프트"]= 'www.microsoft.com'
>>> dic['애플']='www.apple.com'
>>> dic['파이썬']
'www.python.org'
>>> dic['마이크로소프트']
'www.microsoft.com'
>>> dic['애플']
'www.apple.com'
>>> type(dic)
<class 'dict'>
>>> dic
{'파이썬': 'www.python.org', '마이크로소프트': 'www.microsoft.com', '애플': 'www.apple.com'}
>>> dic.keys[]
SyntaxError: invalid syntax
>>> dic.keys()
dict_keys(['파이썬', '마이크로소프트', '애플'])
>>> dic.values()
dict_values(['www.python.org', 'www.microsoft.com', 'www.apple.com'])
>>> dic.items()
dict_items([('파이썬', 'www.python.org'), ('마이크로소프트', 'www.microsoft.com'), ('애플', 'www.apple.com')])
>>> '애플'in dic.keys()
True
>>> '사과'in dic.keys()
False
>>> '애플'in dic.items()
False
>>> dic.pop('애플')
'www.apple.com'
>>> dic
{'파이썬': 'www.python.org', '마이크로소프트': 'www.microsoft.com'}
>>> dic.clear()
>>> dic
{}
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment