Python-nomadCourse 1

Theory

**variable(변수); **
number, 'text'(or "", text has to be surrounded by '' or "")->string, True/False
a=2
b=2

a_string = "like this"
a-number = 3
a_float = 3.12
a_boolean = False
a_none = None

print() function()

**list **
sequence type
days ="Mon,Tue,Wed,Thur,Fri"<--you can't get 3rd day of the week
we use [value]
we need to separate variables;["Mon","Tue","Wed","Thur","Fri"]

**[Python standard library](https://docs.python.org/3/library/)**
print("Mon" in days) 
    *https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range
print(days[2])

tuple

function
def say_hello():
print("hello") <--괄호 안에 있어야지, 앞에 한칸띄고(tab) 해야지 function

def plus(a, b):
print(a + b)

plus(2, 5)

return
def p_plus(a, b):
print(a + b)

def r_plus(a, b):
return(a + b)

p_result = p_plus(2, 3)
r_result = r_plus(2, 3)

print(p_result, r_result)
//p_result 는 return이 없으므로 none
//r_result 는 return이 있으므로 5
//f(x)=y

keyworded arguments
def say_hello(name, age):
return f"Hello {name} you are {age} years old"

hello = say_hello("nico", "12")
print(hello)

code challenge

create a calculater

if else
def plus(a, b)
if CONDITION:
error
else
return a + b //return은 항상 조건안에, else는 if안에

Boolean operation

if
elif => else if

def age_check(age):
print (f"You are {age}.")
if age < 18:
print("You can't drink.")
elif age == 18:
print("You are new to this.")
else:
print("Enjoy your drink.")

age_check(20)

for
for 변수 in sequence
이 때 요 '변수'는 for문이 실행될 때 선언된다. 이름이 뭐든 상관없음.

추가: is 문과 ==문의 차이에 대해서
The == operator compares the value or equality of two objects, whereas the Python is operator checks whether two variables point to the same object in memory. In the vast majority of cases, this means you should use the equality operators == and !=, except when you’re comparing to None

module
you need to import modules
import module