포스트

Basic_IPython

Basic_IPython

Basic_IPython

help()함수로 문서 확인하기

1
len?
1
2
3
Signature: len(obj, /)
Docstring: Return the number of items in a container.
Type:      builtin_function_or_method
1
L = [1, 2, 3]
1
L.insert?
1
2
3
Signature: L.insert(index, object, /)
Docstring: Insert object before index.
Type:      builtin_function_or_method
1
L?
1
2
3
4
5
6
7
8
Type:        list
String form: [1, 2, 3]
Length:      3
Docstring:  
Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.
1
2
3
def square(a):
    """a의 제곱을 반환"""
    return a ** 2
1
square?
1
2
3
4
Signature: square(a)
Docstring: a의 제곱을 반환
File:      c:\users\jiinn\appdata\local\temp\ipykernel_432\2796758577.py
Type:      function

소스코드에 접근하기

1
square??
1
2
3
4
5
6
7
Signature: square(a)
Source:   
def square(a):
    """a의 제곱을 반환"""
    return a**2
File:      c:\users\jiinn\appdata\local\temp\ipykernel_432\2796758577.py
Type:      function

와일드카드 매칭

1
*Warning?
1
2
3
4
5
6
7
8
9
10
11
12
BytesWarning
DeprecationWarning
EncodingWarning
FutureWarning
ImportWarning
PendingDeprecationWarning
ResourceWarning
RuntimeWarning
SyntaxWarning
UnicodeWarning
UserWarning
Warning
1
str. * find *?
1
2
str.find
str.rfind

외부 코드 실행

1
2
%run
myscript.py
1
2
3
1 의 제곱은  1
2 의 제곱은  4
3 의 제곱은  9
1
square(5)
1
25
1
square??
1
2
3
4
5
6
7
Signature: square(x)
Source:   
def square(x):
    """숫자의 제곱을 반환"""
    return x ** 2
File:      d:\a\ai_programming\myscript.py
Type:      function

코드 실행 시간 측정

1
2
%timeit
L = [n ** 2 for n in range(1000)]
1
40.2 µs ± 375 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
1
2
3
4
%%timeit
L = []
for n in range(1000):
    L.append(n ** 2)
1
48 µs ± 1.13 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
이 기사는 저작권자의 CC BY-NC 4.0 라이센스를 따릅니다.