本文内容: 函数
# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Mon May 8 21:01:40 2017
E-mail: Eric2014_Lv@sjtu.edu.cn
@author: DidiLv
"""
# function 1:
def sign(x):
if x > 0:
return 'positive'
elif x < 0:
return 'negative'
else:
return 'zero'
for x in [-1, 0, 1]:
print(sign(x))
# Prints "negative", "zero", "positive"
# function 2:
def hello(name, loud=False):
if loud:
print('HELLO, %s!' % name.upper())
else:
print('Hello, %s' % name)
hello('Bob') # Prints "Hello, Bob"
hello('Fred', loud=True) # Prints "HELLO, FRED!"