首页 / PYTHON / python 第四天
python 第四天
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python 第四天,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1023字,纯文字阅读大概需要2分钟。
内容图文
class Game_object:
def __init__(self,name):
self.name=name
def pickUp(self):
pass ##这里原本不允许函数为空,所以可以使用pass 先略过。
#put code here
#to the player‘s collectiong
class Coin (Game_object):
def __init__(self,value):
Game_object.__init__(self)
self.value =value
def spend(self,buyer,seller):
pass
#put code here
创建个模板
#this is a module.files
def c_to_f(celsius):
fahrenheit = celsius * 9.0 / 5 + 32
return (fahrenheit) #注意一定加括号,否则在python 3.0以后版本会报错
‘return‘ outside function
保存为my_module.py
import my_module #调用这个模块 (这里my_module 就是个命名空间)
celsius =float(input("Enter a temperature in Celesius:"))
fahrenheit =my_module.c_to_f(celsius) 注意调用模块的函数一定要模块和函数都要写上。
print ("Thant‘s",fahrenheit,"degrees Fahrenheit")
以上的也可以用
from my_module import c_to_f
celsius =float(input("Enter a temperature in Celesius:"))
fahrenheit =c_to_f(celsius) #这里就不用指明哪个模块的哪个函数。直接使用函数就行
print ("Thant‘s",fahrenheit,"degrees Fahrenheit")
本文出自 “姑苏城” 博客,请务必保留此出处http://ji123.blog.51cto.com/11333309/1965758
原文:http://ji123.blog.51cto.com/11333309/1965758
内容总结
以上是互联网集市为您收集整理的python 第四天全部内容,希望文章能够帮你解决python 第四天所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。