프로그래밍/Python
이론 정리
moving
2021. 4. 17. 10:14
728x90
1. Data Types of Python
a_string = "like this" #str
a_number = 3 #int
a_float = 3.12 #float
a_boolean = False
a_none = None #존재하지 않음
2. Lists in Python (Mutable Sequence Types)
days = ["Mon","Tue","Wed","Thur","Fri"]
docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range
Built-in Types — Python 3.9.4 documentation
The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions. Some collection classes are mutable. The methods that add, subtract,
docs.python.org
3. Tuples and Dicts
days = ("Mon","Tue","Wed","Thur","Fri")
nico = {
"name": "Nico",
"age": 29,
"korean": Ture,
"fav_food": ["Kimchi","Sashimi"]
}
4. Creating a Your First Python Function
def say_hello():
print("hello")
5. Function Arguments
def plus(a, b):
print(a + b)
plus(2, 5)
6. Returns
def plus(a, b):
return a + b
result = plus(2, 4)
print(result)
7. Keyworded Arguments
def plus(a, b):
return a + b
result = plus(b=2, a=4)
print(result)
def say_hello(name, age):
return f"Hello {name} you are {age} years old"
hello = say_hello(name="nico", age="12")
print(hello)
8. Conditionals part One
def plus(a, b):
if type(b) is int or type(b) is float:
return a + b
else:
return None
print(plus(12, 1.2))
9. if else and or
def age_check(age):
print(f"your are {age}")
if age < 18:
print("you cant drink")
elif age == 18:
print("you age new to this!")
elif age > 20 and age < 25:
print("you are still kind of young")
else:
print("enjoy your drink")
age_check(29)
10. for in
days = ("Mon", "Tue", "Wed", "Thu", "Fri")
for day in days:
print(day)
days = ("Mon", "Tue", "Wed", "Thu", "Fri")
for day in days:
if day is "Wed":
break
else:
print(day)
11. Modules
import math
#올림하는 함수
print(math.ceil(1.2))
from math import ceil, fsum
print(ceil(1.2))
print(fsum([1, 2, 3, 4, 5, 6]))