import keyword as kwd
print(kwd.kwlist)
print()
print(len(kwd.kwlist))
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] 33
print(abs(3))
print(abs(-3))
3 3
print(max(1, 2))
print(max([1, 2, 3]))
print(max("python"))
2 3 y
print(min(1, 2))
print(min([1, 2, 3]))
print(min("python"))
1 1 h
print(pow(2, 4))
print(pow(3, 3))
print(pow(2, -1))
16 27 0.5
print(chr(97))
print(chr(65))
print(chr(48))
a A 0
str(object='') -> str
print(str(3))
print(str([1, 2]))
a = 3
3 [1, 2]
range(stop) -> range object
range(start, stop[, step]) -> range object
print(range(10))
print(range(3, 10))
print(range(3, 10, 2))
print()
print(list(range(10)))
print(list(range(3, 10)))
print(list(range(3, 10, 2)))
range(0, 10) range(3, 10) range(3, 10, 2) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [3, 4, 5, 6, 7, 8, 9] [3, 5, 7, 9]
print(type(-1))
print(type('abc'))
print(type([1, 2, 3]))
print(type(range(10)))
<class 'int'> <class 'str'> <class 'list'> <class 'range'>
def all(iterable):
ย ย ย ย for element in iterable:
ย ย ย ย ย ย ย ย if not element:
ย ย ย ย ย ย ย ย ย ย ย ย return False
ย ย ย ย return True
def any(iterable):
ย ย ย ย for element in iterable:
ย ย ย ย ย ย ย ย if element:
ย ย ย ย ย ย ย ย ย ย ย ย return True
ย ย ย ย return False
print(all([1]))
print(all([1, False]))
print()
print(any([1]))
print(any([1, False]))
# ์กฐ๊ฑด 1, ์กฐ๊ฑด 2
k = 1
l = 2
conditions = all([k == 1, l == 2])
if conditions:
print(11111111111111)
True False True True 11111111111111
ํ์ด์ฌ ์๋ณ์๋ ๋ณ์, ํจ์, ๋ชจ๋, ํด๋์ค ๋๋ ๊ฐ์ฒด๋ฅผ ์๋ณํ๋๋ฐ ์ฌ์ฉ๋๋ ์ด๋ฆ์ด๋ค.
์๋ณ์์ ์กฐ๊ฑด
๋์๋ฌธ์ ๊ตฌ๋ณํจ
์๋ณ์๋ ๋ฌธ์ A~Z ๋๋ a~z๊ณผ ์ธ๋๋ฐ(_)๋ก ์์ํ ์ ์๋ค.
์๋ณ์ ์ฒซ ์์์ ์ ์ธํ๊ณ ์๋ณ์ ๋ด์ ์ซ์(0~9)๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
ํน์๋ฌธ์ @, $, % ๋ฑ์ ์๋ณ์์ ์ด๋ ์๋ฆฌ์๋ ์ฌ ์ ์๋ค.
์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ ์๋ณ์๊ฐ ๋ ์ ์์
print(str(12345))
12345
str = 'abc'
print(str(12345))
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-23-bcb57bba362e> in <module> 1 str = 'abc' 2 ----> 3 print(str(12345)) TypeError: 'str' object is not callable
a = 1
print(a)
1
print(b)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-25-67e500defa1b> in <module> ----> 1 print(b) NameError: name 'b' is not defined
b = 2
print(b)
del b
print(b)
2
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-17-5787c62d3943> in <module> 3 4 del b ----> 5 print(b) NameError: name 'b' is not defined
a = 1
# b = 2
# a = 3
print(b)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-26-489915ee571b> in <module> 2 # b = 2 3 # a = 3 ----> 4 print(b) NameError: name 'b' is not defined
"""์ฌ๊ธฐ๋ถํฐ
์ฌ๊ธฐ๋
math.min() <-- ๊ทธ์ ๋ฌธ์์ด
์ฃผ์์
๋๋ค."""
import math
a = 1
b = 3
if (a == 1) and \
(b == 3):
print('connected lines')
connected lines
a = 1
b = 3
if (a == 1) and (b == 3):
print('connected lines')
connected lines
a = 1
b = a
1 + 3 = a
File "<ipython-input-27-cb35bd179dea>", line 1 1 + 3 = a ^ SyntaxError: can't assign to operator
a = 1
a = a + 1
print(a)
2
c, d = 3, 4
print(c, d)
x = y = z = 0
print(x, y, z)
e = 3.5; f = 5.6
print(e, f)
3 4 0 0 0 3.5 5.6
e = 3.5; f = 5.6
e, f = f, e
print(e, f)
5.6 3.5
a = (b = c + d)
File "<ipython-input-39-79d71c957091>", line 1 a = (b = c + d) ^ SyntaxError: invalid syntax
a = 1
a += 4
print(a)
5
a = 10
a -= 3
print(a)
7
a = 10
a *= 2+3
print(a)
50
import copy
a = copy.deepcopy(1)
if a is 1:
print("1์ ๋ฏธ๋ฆฌ ํ ๋น๋์ด์ง ๊ฐ์ฒด")
b = copy.deepcopy(256)
if b is 256:
print("256๋ ๋ฏธ๋ฆฌ ํ ๋น๋์ด์ง ๊ฐ์ฒด")
c = copy.deepcopy(257)
if not(c is 257):
print("257๋ถํฐ๋ ๋ฏธ๋ฆฌ ํ ๋น๋์ด์ง ๊ฐ์ฒด๊ฐ ์๋๋ค.") #mac os ๊ธฐ์ค
1์ ๋ฏธ๋ฆฌ ํ ๋น๋์ด์ง ๊ฐ์ฒด 256๋ ๋ฏธ๋ฆฌ ํ ๋น๋์ด์ง ๊ฐ์ฒด
a = [1,2,3]
b = [10, a, 20]
c = ['x', a, 'y']
print(a)
print(b)
print(c)
[1, 2, 3] [10, [1, 2, 3], 20] ['x', [1, 2, 3], 'y']
a[1] = 1000
print(a)
print(b)
print(c)
[1, 1000, 3] [10, [1, 1000, 3], 20] ['x', [1, 1000, 3], 'y']
name = input('name?')
name?๊น์ฃผ๋ด
print(name)
์ ์งฑ๊ตฌ
int(x=0) -> integer int(x, base=10) -> integer
print(int(3.14)) # For floating point numbers, this truncates towards zero. 0์ด ๋๋ ๋ฐฉํฅ์ผ๋ก ์์ซ์ ์ดํ๋ฅผ ๋ฒ๋ฆผ
print(int()) # return 0 if no arguments are given. ๊ทธ๋ฅ int()๋ 0์ ๋ฆฌํด
3 0
k = input('str : ')
print(k)
print(type(k))
print()
k = int(input('int : '))
print(k)
print(type(k))
str : ์งฑ๊ตฌ๋ ๋ชป๋ง๋ ค ์งฑ๊ตฌ๋ ๋ชป๋ง๋ ค <class 'str'> int : 100 100 <class 'int'>
# Python3์์ input()์ ๊ธฐ๋ฅ
# Read a string from standard input. The trailing newline is stripped.
? min
print(4 + 5, 4 - 2)
9 2
print(1); print(2)
1 2
print(1),
print(2)
print()
print(1)
print(2)
1 2 1 2
end=' '
๋ฅผ ์ฌ์ฉ (๋ํดํธ๋ end='\n'
)print(1, end=", ")
print(2)
print()
print(1, end=" ")
print(2)
1, 2 1 2
string = "{}-2ํ๊ธฐ"
print(string.format(2020))
2020-2ํ๊ธฐ
string = "๋์ ์๋ ฅ์ {0:10.5f}์ด๊ณ ๋ฐ ์ฌ์ด์ฆ๋ {1:1d}ํ๊ธฐ"
print(string.format(1., 2))
๋์ ์๋ ฅ์ 1.00000์ด๊ณ ๋ฐ ์ฌ์ด์ฆ๋ 2ํ๊ธฐ
print(12 + 'spam')
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-70-5df4a4acc35b> in <module> ----> 1 print(12 + 'spam') TypeError: unsupported operand type(s) for +: 'int' and 'str'
print('12' + 'spam')
12spam
์ฐธ๊ณ ๋ฌธํ: ํ์ด์ฌ(์ดํ๊ฐ์)(๊ฐ์ ํ VER.2), ์ด๊ฐ์ฑ, FreeLec, 2005๋ 8์ 29์ผ