栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Day11—100days of python coding

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Day11—100days of python coding

Funtions with Outputs
def my_function():
    result = 3*2
    return result

when call my_function()

my_function() is replaced by the return

then we can save this result as another variable

like:

output = my_function

Return tells the computer it is the end and won't execute later.

The return keyword will exit the function and prevent the rest of the code from being executed.

if True:
the following will be executed; if False: the follwing will not be executed  Docstrings

"""(3)"""(3)

it is used to documente the things you want

def format_name(f_name, l_name):
     """Take a first and last name and format it to return the title case version of the name"""

Also,you can use comment instead.But it can not work like docstrings

How to create a dictionary at the same time adding multiple keys and values in it?
operation={
"love"=A * B ,
"Trust"= A ** B
}
operations={
    "+":add,
    "-":subtract,
    "*":multiply,
    "/":divide
}
# This dictionary will act as a mean to call the operation
#How can we call this funtion?
# 1)pick the key
# like this: opertions["+"]
# and we can store it into a variable ,for example we can call it function
# So  function = operations["+"]
# Then we can call it funtin(n1,n2)
# That partly explains why we just store *add/ subtract* in the value part
Print Vs. Return

*BUT there is a question:

   What if we wanted to take the output that comes from calling this function and instead of just storing it inside a variable and printed it out? What if we wanted to pass it to another function as an input?

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/357379.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号