Chapter 2

7418 단어 apt
1. 기호 >> 는 출력의 방향을 정하는 데 사용됩니다.
>>> import sys

>>> print >> sys.stderr,'Fatal error!'

Fatal error!

2、raw_input () 내장 함수는 마크업 입력을 읽습니다. 사용자의 입력은 문자열 형식입니다. 정형으로 바뀌어야 합니다.
1 >>> num=raw_input("Enter a num: ")

2 Enter a num: 2341

3 >>> print 'the num is: %d' % int(num)

4 the num is: 2341

3. Python은 C 언어의 자동 증가 1 및 자동 감소 1 작업을 지원하지 않습니다.
더하기 기호(+) 사용자 문자열의 연결 연산, 곱하기 기호(*)는 문자열의 중복에 사용됩니다.
4, 클래스
인스턴스가 생성될 때 __init__() 가 자동으로 호출됩니다.
self.__class__.__name__되돌아오는 것은 이 종류의 클래스 이름이다.
dir()는 Python에서 제공하는 API 함수로, dir() 함수는 자동으로 검색 __를 포함한 객체의 모든 속성을 찾습니다.dict__에 나열된 속성입니다.
>>>dir(FooClass)

>>>['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'showname', 'version']

>>>FooClass.__dict__()

>>>{'__module__': '__main__', 'version': 0.1, 'showname': <function showname at 0x10994e578>, '__dict__': <attribute '__dict__' of 'FooClass' objects>, '__weakref__': <attribute '__weakref__' of 'FooClass' objects>, '__doc__': 'optional documentation string', '__init__': <function __init__ at 0x109945ed8>}

 
 
5, 모듈
>>> import sys

>>> sys.platform

'darwin'

>>> sys.version

'2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
' >>> sys.stdout.write("Hello dear!
") #write() Hello dear! >>> sys.stdout.write("Hello dear!") Hello dear!>>>

좋은 웹페이지 즐겨찾기