투케이2K

53. (python/파이썬) 삼항식을 사용해 if else 조건 분기 처리 실시 본문

Python

53. (python/파이썬) 삼항식을 사용해 if else 조건 분기 처리 실시

투케이2K 2022. 8. 3. 08:33
반응형

[개발 환경 설정]

개발 툴 : SublimeText (PyScript)

개발 언어 : python

 

[소스 코드]

<!DOCTYPE HTML>
<html lang="ko">
<head>
    <title>WebTest</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">



    <!-- [pyScript 사용 관련 CDN 설정 실시] -->
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>




    <!-- 
    // -----------------------------------------
    [요약 설명]
    // -----------------------------------------
    1. 삼항식은 조건이 만족하는 경우와 만족하지 않은 경우를 쉽게 표시할 수 있습니다
    // -----------------------------------------
    2. 파이썬에서 삼항식을 사용하기 위해서는 : [true 결과] if [조건] else [else 결과] 방법으로 문법을 사용합니다
    // -----------------------------------------
     -->




    <!-- [pyScript 구문 정의 실시] -->
    <py-script>
        print("=====================================")
        print("[main start]")
        print("=====================================")


        # [초기 변수 선언 실시]
        int_Data = 5


        # [삼항식을 사용해 조건 처리 실시]
        result_Data = "5 이상" if int_Data >= 5 else "5 미만" 


        # [결과 출력 실시]
        print("int_Data : {}".format(int_Data))
        print("result_Data : {}".format(result_Data))
       
    </py-script>
    
</head>





<!-- [body 콘텐츠 작성] -->
<body>
</body>


</html>
 

[결과 출력]

 

 

반응형
Comments