다행히 오늘 주제는 내용이 많지 않아서 금방 끝낼 수 있었다.
True, False에 대한 내용이다.
(그런데, 문제 푸는 것보다 포스팅하는 게 더 오래 걸리는 건 어떻게 해결해야 할까 생각 좀 해 봐야겠다)
Chapter 6. Conditions
Python uses boolean logic to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
1. The "and" and "or" boolean operators allow building complex boolean expressions.
2. The "in" operator could be used to check if a specified object exists within an iterable object container.
3. A statement is evaulated as true if one of the following is correct: 1. The "True" boolean variable is given, or calculated using an expression, such as an arithmetic comparison. 2. An object which is not considered "empty" is passed.
Here are some examples for objects which are considered as empty: 1. An empty string: "" 2. An empty list: [] 3. The number zero: 0 4. The false boolean variable: False.
4. Unlike the double equals operator "==", the "is" operator does not match the values of the variables, but the instances themselves.
5. Using "not" before a boolean expression inverts it.
Exercise
# change this code
number = 16
second_number = []
first_array = [1, 2, 3]
second_array = [1,2]
if number > 15:
print("1")
if first_array:
print("2")
if len(second_array) == 2:
print("3")
if len(first_array) + len(second_array) == 5:
print("4")
if first_array and first_array[0] == 1:
print("5")
if not second_number:
print("6")
'IT World > Python' 카테고리의 다른 글
Python Training Day5. Functions (0) | 2022.12.16 |
---|---|
Python Training Day4. Loops (0) | 2022.12.15 |
Python Training Day1, Day2. String Formatting, Basic String Operations (0) | 2022.12.13 |
Python Training Day5. Basic Operators (0) | 2022.12.08 |
Python Training Day3&4. Numbers, Strings, Lists (0) | 2022.12.07 |
댓글