파이썬 기본문


고급 Python 튜토리얼을 배우기 전에, 이번 글에서는 Python에서 일반적으로 사용되는 몇 가지 기본 명령문을 요약하고, 이러한 일반적으로 사용되는 Python 명령문의 용도와 표준 형식을 간략하게 소개했습니다. 귀하의 편의를 위해 함께 정리할 수 있습니다.

(1), 할당: 변수 참조 값 만들기
a,b,c='aa','bb','cc'

(2), 호출: 함수 실행
log.write('spam,name' )

Print, 출력: print 객체 호출, print 문
print ('abc')

(3) if, elif, else: 조건문 선택, if 문, else 및 elif 문

if 'iplaypython' in text:
    print (text)

(4) for , else: 시퀀스 반복

for x in list:
    print x

(5), while, else: 일반 루프 문

while a > b :
    print 'hello'

(6), pass: 자리 표시자(비어 있음)

while True:
    pass

(7), break: 루프 종료

while True:
    if exit:
        break

(8) , 계속: 현재 루프를 건너뛰고 루프를 계속합니다.

while True:
    if skip:
        continue

다음 명령문은 비교적 큰 프로그램에서 사용됩니다. 함수, 클래스, 예외 및 모듈과 관련하여 메소드의 목적과 형식도 간략하게 소개합니다.

(9), def: 함수 및 메서드 정의

def info(a,b,c=3,*d):
    print (a+b+c+d[1])

(10), 반환: 함수 반환 값

def info(a,b,c=3,*d):
    return a+b+c+d[1]

(11), python 전역: 네임스페이스, 범위

x = 'a'
def function():
    global x ; x = 'b'

(12), 가져오기: 액세스, 모듈 가져오기
import sys

(13), from: 속성 액세스
from sys import stdin

(14), 클래스: 객체 생성, 클래스 정의 메서드

class Person:
    def setName(self,name):
        self.name = name
    def getName(self):
        return self.name
    def greet(self):
        print 'hello,%s' % self.nameclass Person:
    def setName(self,name):
        self.name = name
    def getName(self):
        return self.name
    def greet(self):
        print 'hello,%s' % self.names

(15), try, Except, finally: Python 캡처 Exception

try:
    action()
except:
    print ('action error')

(16), raise: 예외 트리거

raise Endsearch(위치)

(17), 주장: Python 주장, 디버깅 확인

assert a>b,'a roo small'

위는 다음의 요약입니다. 기초 수강생을 위한 방법. Python 초보자의 경우 해당 설명을 클릭하면 구체적인 작업 방법 소개를 볼 수 있습니다.