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?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值