스파르타 AI-8기 TIL(9/28)
Text formatting
1. INT, STRING, VARIABLES
1. putting INT data into text
Ex.
result -> I eat 3 apples
%d -> for INT data type
2. putting STRING data into text
result -> I eat 3 apples
%s -> for STRING data type
BUT, must covered with "" -> because it's the string
3. putting VARIABLES data into text
result = I ate 3 apples
But must consider the type of data too. number = 3 = INT = %d
Or
I can put data of more than 2
Result -> today, I ate 2 apples
But -> must covered with () and separated by ,
codes
%s -> STRING
%c -> CHARACTER
%d -> INT
%f -> FLOAT
%% -> just % itself (showing % in the text)
AND for %s,
%s can be used for all types of data
Result ->
I have 3 apples
rate is 3.234
Input
-> makes the input type data and returns the input data
Ex.
then It will show this in the terminal
name:
If I write Kevin Kim here,
name: Kevin Kim
result -> Kevin kim
It will return the value of the input data
f-string formatting
f -> bring data
ex.
f-string will bring name and age variables and make them usable in the text using {}.
Global Variable -> Can be used in the whole program
Local Variable -> Only available in certain areas (function etc)
Operator
산술 연산자 (Arithmetic Operators)
비교 연산자 (Comparison Operators)
논리 연산자 (Logical Operators)
대입 연산자 (Assignment Operators)
비트 연산자 (Bitwise Operators)
맴버십 연산자 (Membership Operators)
식별 연산자 (Identity Operators)
1. Arithmetic Operators
+ -> plus
- -> minus
* -> multiply
/ -> dividing
% -> will only get the remains from dividing
** -> Exponent
// -> will only get the share
2. Comparison Operator
== -> return true if values are same (3 == 3) -> true
!= -> return true if values are different (3 != 4) -> true
> -> return true if the left value is bigger (4 > 3) -> true
< -> return true if the right value is bigger (3 < 4) -> true
>= -> return true if the left value is bigger or the same (3 >= 3) or (4 >= 3) -> true
<= -> return true if the right value is bigger or the same (3 <= 3) or (3 <= 4) -> true
3. Logical Operators
and -> return true if both conditions are satisfied
or -> return true if one of the conditions is satisfied
not -> reverse logical value
4. Assignment Operators
= -> same as -> a= 5
+= -> same as a = a + 5
-= -> same as a = a - 5
*= same as a = a * 5
/= same as a = a / 5
%= same as a = a % 5
**= same as a = a ** 5
//= -> same as a = a // 5
5. Bitwise Operators(Binary)
1. Binary to Decimal
2. Decimal to Binary
& -> same as and
Ex.
a= 101101
b= 010111
----------------
000101 -> returns 1 or 0 if that line matches correctly
| -> same as or
Ex.
a= 101101
b= 010111
----------------
111111 -> return 1 or 0 if that line doesn't match correctly
^ -> reverse of or
Ex.
a= 010101
b= 010111
----------------
101010 -> like 0 = 0 -> 1, 1 = 1 -> 0 1 = 0 -> 1
~ -> same as not(I'm not sure about it but let's remember this as (x+1)*1
Ex.
x = 5
print(~5) -> result is -6
<< -> Just moving the numbers to the left
Ex.
b = 1(01)
b << 1 -> (10) = 2
b << 2 -> (100) = 4
>> -> Just moving the numbers to the right
6. Membership Operators
in -> return true if the chosen value is in the given text
Ex.
"d" in "dragon" -> true
not in -> return true if the chosen value is not in the given text
Ex.
"d" not in "apple" -> true
7. Identity Operators
Is -> Check if the two variables have the same object
Is not -> Check if the two variables have some object
Good Night