Python 예제
## Comments
# This is a one-line Python comment - code blocks are so useful !
""" This type of comment is used to document the purpose of funtions and classes."""
## Declaration/Initialization
# Remember values, not variables, have data types.
# A variable can be reassigned to containe a different data type.
answer = 42
answer_some = "The answer is 42."
## Data Types
boolean = True
number = 1.1
string = "Strings can be declared with single or double quotes."
list_some = ["Lists can have", 1, 2, 3, 4, "or more types together!"]
tuple_some = ("Tuples", "can have", "more than", 2, "elements!")
dictionary = {'one': 1, 'two': 2, 'three': 3}
variable_with_zero_data = None
print(list_some)
print(tuple_some)
print(dictionary)
## Simple Logging
print ("Printed!")
## Conditionals
def test_func(cake):
if cake == "delicious":
return "Yes, please!"
elif cake == "okay":
return "I'll have a small piece."
else:
return "No, thank you."
## Loops
for item in list_some:
print (item)
def is_big(total, max_val, values):
i = 0
while (total < max_val):
total += values[i]
i += 2
return total
## Functions
def divide(dividend, divisor):
quotient = dividend / divisor
remainder = dividend % divisor
return quotient, remainder
def caculate_stuff(x, y):
(q, r) = divide(x, y)
print (q, r)
## classes
class person(object):
def __init__(self, name, age):
self.name = name
self.age = age
def birthday(self):
self.age += 1
'Web Tech. > Python' 카테고리의 다른 글
Udacity.com Nanodegree(미세 전공) 학위 (0) | 2017.07.07 |
---|---|
Python Lists 강좌 ( 원문, google.com ) (0) | 2017.07.05 |
Python, Web 보안 (기초) (0) | 2017.07.04 |
vagrant up, Authentication failure. Retrying 발생시 (0) | 2017.05.16 |
빅데이타와 Python (0) | 2017.02.07 |