Python 예제

Web Tech./Python 2017. 7. 4. 18:42
노출되는 이미지가 불편하시겠지만 양해를 구합니다. 노출, 클릭등에 관한 자료로 활용 중입니다.

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

    



블로그 이미지

StartGuide

I want to share the basic to programming of each category and how to solve the error. This basic instruction can be extended further. And I have been worked in southeast Asia more than 3 years. And I want to have the chance to work another country.

,