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

Upload New File

parent f127fee1
Branches
No related tags found
No related merge requests found
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.
>>> 9 in range(10)
True
>>> 10 in range(10)
False
>>> 0 in range(10)
True
>>> range(10)
range(0, 10)
>>> dic = {"애플": "www.apple.com".}
SyntaxError: invalid syntax
>>> dic = {"애플": "www.apple.com".}
SyntaxError: invalid syntax
>>> dic = {"애플": "www.apple.com ".}
SyntaxError: invalid syntax
>>> dic = {"애플": "www.apple.com".
"파이썬": "www.python.org"
"마이크로 소프트": "www.microsoft.com"}
SyntaxError: invalid syntax
>>> dic = {"애플": "www.apple.com",
"파이썬": "www.python.org",
"마이크로 소프트": "www.microsoft.com"}
>>> for k,v in dic.items():
print (k,v)
애플 www.apple.com
파이썬 www.python.org
마이크로 소프트 www.microsoft.com
>>> for i in dic:
print(i)
애플
파이썬
마이크로 소프트
>>> for i in dic:
print(i,dic[i])
애플 www.apple.com
파이썬 www.python.org
마이크로 소프트 www.microsoft.com
>>> for i in dic:
print(i,dic{i})
SyntaxError: invalid syntax
>>> for i in dic:
print(i,dic(i))
Traceback (most recent call last):
File "<pyshell#20>", line 2, in <module>
print(i,dic(i))
TypeError: 'dict' object is not callable
>>> for i in dic:
if(i == "애플")
SyntaxError: invalid syntax
>>> for i in dic:
if(i == "애플"):
print(i,dic[i])
애플 www.apple.com
>>> for i in dic:
if(i == "애플"):
print(i,dic[i])
break
애플 www.apple.com
>>> def abs(x)
SyntaxError: invalid syntax
>>> def abs(x):
if x< 0:
return -x
return x
>>> abs(100)
100
>>> abs(-100)
100
>>> type(abs)
<class 'function'>
>>> def minus(x):
x = -x
>>> minus(100)
>>> minus(-100)
>>> def minus(x):
x = -x
return x
>>> minus(-100)
100
>>> minus(100)
-100
>>> def print_personnel(name, position = "staff", nationality="Korea"):
print("name = {0}",format(name))
print("position = {0}",format(position))
print("nationality = {0}",format(nationality))
>>> print("장범진")
장범진
>>> print_personnel("장범진")
name = {0} 장범진
position = {0} staff
nationality = {0} Korea
>>> def print_personnel(name, position = "staff", nationality="Korea"):
print('name = {0}',format(name))
print('position = {0}',format(position))
print('nationality = {0}',format(nationality))
SyntaxError: unexpected indent
>>> def print_personnel(name, position = "staff", nationality="Korea"):
print('name = {0}',format(name))
print('position = {0}',format(position))
print('nationality = {0}',format(nationality))
>>> print_personnel("장범진")
name = {0} 장범진
position = {0} staff
nationality = {0} Korea
>>> def print_personnel(name, position = "staff", nationality="Korea"):
print('name = {0}'.format(name))
print('position = {0}'.format(position))
print('nationality = {0}'.format(nationality))
SyntaxError: unexpected indent
>>> def print_personnel(name, position = "staff", nationality="Korea"):
print('name = {0}'.format(name))
print('position = {0}'.format(position))
print('nationality = {0}'.format(nationality))
>>> print_personnel("장범진")
name = 장범진
position = staff
nationality = Korea
>>> def fl(*a):
for x in a:
print(x)
>>> fl(123,456)
123
456
>>> fl("이환용",2024)
이환용
2024
>>> type(*a)
Traceback (most recent call last):
File "<pyshell#70>", line 1, in <module>
type(*a)
NameError: name 'a' is not defined
>>> type(*)
SyntaxError: invalid syntax
>>> int *a
Traceback (most recent call last):
File "<pyshell#72>", line 1, in <module>
int *a
NameError: name 'a' is not defined
>>> type(fl)
<class 'function'>
>>> def merge_string(*text_list):
result = ''
for s in text_list:
result = result +s
returtn result
SyntaxError: invalid syntax
>>> def merge_string(*text_list):
result = ''
for s in text_list:
result = result +s
return result
>>> merge_string('아버지','','방에','들어가신다')
'아버지가방에들어가신다'
>>> def fl(*a):
for x in a:
print(type(x),x)
>>> fl((1,2,3),456,"장범진",{"a":100})
<class 'tuple'> (1, 2, 3)
<class 'int'> 456
<class 'str'> 장범진
<class 'dict'> {'a': 100}
>>> def scope_test():
a=100
print(a)
>>> a=100
>>> a=200
>>> scope_test(a)
Traceback (most recent call last):
File "<pyshell#91>", line 1, in <module>
scope_test(a)
TypeError: scope_test() takes 0 positional arguments but 1 was given
>>> scope_test()
100
>>> a
200
>>> def scope_test():
a=100
print(a * b)
>>> scope_test
<function scope_test at 0x000001AF760BF598>
>>> scope_test()
Traceback (most recent call last):
File "<pyshell#97>", line 1, in <module>
scope_test()
File "<pyshell#95>", line 3, in scope_test
print(a * b)
NameError: name 'b' is not defined
>>> def scope_test():
global a
a = 1
print('a:{0}'.format(a))
>>>
>>> a= 0
>>> scope_test()
a:1
>>> print("a")
a
>>> print("a:{0}".format(a))
a:1
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment