본문 바로가기
Python 배우기

functions.py

by 노화방지 Anti-aging Hairstyle 2016. 3. 10.
반응형
def hello_world():  # function named my_function
print("Hello, World!")

for i in range(5):
hello_world() # call function defined above 5 times

print('I want to be a function')
print('I want to be a function')
print('I want to be a function')

def fun(): # Define a function to replace duplicate lines in the file.
print('I want to be a function')

for i in range(3):
fun()


산출물 (Output)

Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
I want to be a function
I want to be a function
I want to be a function
I want to be a function
I want to be a function
I want to be a function

* Functions are a convenient way to divide your code into useful blocks, make it more readable and help reuse it.
Functions are defined using the keyword "def", followed by the function's name.


반응형

'Python 배우기' 카테고리의 다른 글

default_parameter.py  (0) 2016.03.11
param_args.py  (0) 2016.03.10
continue_keyword.py  (0) 2016.03.10
break_keyword.py  (0) 2016.03.10
while_loop.py  (0) 2016.03.10

댓글