Python Basic - Get Value and Math Expression

DevSmiler·2020년 2월 2일
0

Python Basic

목록 보기
3/11

입력 받는 방법 input()

value = input()이 방법으로 문자를 받을수 있습니다. 하지만 숫자로서 사용을 하려고 하면 치환을 해주어야 합니다. int(), float()을 이용해서 치환을 하면 됩니다.

num = int(input())//3을 입력한다 가정

print(num)

result : 3

Variable Math Expressions

  • 기본 사칙 연산
    +
    - -
    /
    - *

    기본적으로 덧셈 뺄셈 곱셈 나누기 등 사칙연산을 지원한다.

     1 + 1 -> 2
    1 * 2 -> 2
    1 / 2 -> 0.5(float)
    	 1 - 2 -> -1 
  • 그 외의 기본 연산

    • %
    • +=
    • -=
    • /=
    • *=
    • **
    • %=

    % 연산

    나누기 연산의 나머지 값을 리턴해준다.
     3 % 2 

    result : 1

    +=, -=, /= , *=, %= 연산

    	num = 2 

    num += 2 == (num = num + 2)
    result : 4

    num -= 2 == (num = num -2)
    result : 0

    num /= 2 == (num = num / 2)
    result : 1

    num = 2 == (num = num 2)
    result : 4

    num %= 3 == (num = num % 3)
    result: 2

    제곱 (**)

    10의 2제곱

    10 ** 2
    result : 100

profile
A ship is always safe at the shore, but that is not what it is built for - Albert Einstein

0개의 댓글