1def sign(x):
2 if x > 0:
3 return 'positive'
4 elif x < 0:
5 return 'negative'
6 else:
7 return 'zero'
8for x in [-1, 0, 1]:
9 print sign(x)
10# Prints "negative", "zero", "positive"
我们常常使用可选参数来定义函数:
1def hello(name, loud=False):
2 if loud:
3 print 'HELLO, %s' % name.upper()
4 else:
5 print 'Hello, %s!' % name
6hello('Bob') # Prints "Hello, Bob"
7hello('Fred', loud=True) # Prints "HELLO, FRED!"
函数还有很多内
容,可以查看文档。
类Classes
Python对于类的定义是简单直接的: 1class Greeter(object):
2 # Constructor
3 def __init__(self, name):
4 self.name = name # Create an instance variable
5 # Instance method
6 def greet(s
最后
以上就是呆萌钢铁侠最近收集整理的关于python调用函数后endofstatementexpected_斯坦福CS231n深度学习课程笔记翻译(一)的全部内容,更多相关python调用函数后endofstatementexpected_斯坦福CS231n深度学习课程笔记翻译(一)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复