이 블로그 검색

2023년 8월 8일 화요일

Summary of Operators in Python

Types of Arithmetic Operators in Python

Symbol Description Return Value
+ Addition Varies depending on the data types
- Subtraction Varies depending on the data types
* Multiplication Varies depending on the data types
/ Division Returns a floating-point value
// Floor Division Returns an integer value
% Modulus Returns a floating-point value
** Exponentiation Varies depending on the data types
and Logical AND Returns True or False
or Logical OR Returns True or False
< Less than Returns True or False
> Greater than Returns True or False
<= Less than or equal to Returns True or False
>= Greater than or equal to Returns True or False
== Equal to Returns True or False

+, -, *, /, //, %, **, <, >, <=, >= Table

A B Result
int int int A + B result
int float float A + B result
int bool-True int A + 1 result
int bool-False int A + 0 result
int None TypeError
int string TypeError
float bool-True float A + 1 result
float bool-False float A + 0 result
float None TypeError
float string TypeError
bool None TypeError
bool string TypeError
None string TypeError

In the early days of computer generation and the inception of programming languages, 1 represented True, and 0 represented False.

== Table

A B Result
int int Boolean result
int float Boolean result
int bool Boolean result
int None Boolean result
int string Boolean result
float bool Boolean result
float None Boolean result
float string Boolean result
bool None Boolean result
bool string Boolean result
None string Boolean result

Unlike Java, this doesn't compare classes. It compares values. Since all are objects, these comparisons are possible.

and, or Truth Tables

A B and or
False False False False
False True False True
True False False True
True True True True

As shown in the table above, "and" and "or" are operations on True and False.

When different data types are used, the "or" operation returns the value of B, while the "and" operation returns the value of A.

댓글 없음:

댓글 쓰기

Logic Gate Truth Tables & Definitions

Logic Gate Truth Tables Java Code !A // NOT A&B // AND ~(A&B) // NAND A|B // OR ~(A|B) // XOR A^B // XOR ~(A^B) // XNOR ~A // Inve...