繁体   English   中英

Python局部变量到全局变量

[英]Python local variable to global variable

我正在尝试编写具有功能的模块化脚本

-Function 1 age = input("告诉我你的年龄:")

-Function 2 weight = input("告诉我你的体重:")

-函数3生日=输入(“告诉我你的生日:”)

最后,我想在功能之外发送邮件,例如:

mail_body = 年龄 + 体重 + 生日

谢谢你的时间!

您可以在函数末尾使用 return 命令将信息传递到调用它的位置

mail_body = age + weight + birthday
return mail_body

例如,如果您的函数是mailinfo()那么您可以像这样处理信息

mail_body = mailinfo() #after using return command in function

或者您可以在程序开始时将mail_body声明为全局函数

mail_body = "placeholder"
global mail_body

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM