[英]New to Python need to create a function [on hold]
Given a list of numbers that is at least length of 2, write a function called XT that returns the sum of the first 2 elements in the list.给定一个长度至少为 2 的数字列表,编写一个名为 XT 的 function,它返回列表中前 2 个元素的总和。
With such a question google would be the better source of information.有了这样的问题,谷歌将是更好的信息来源。
def xt(lst):
return lst[0] + lst[1]
print(xt([1, 2, 3]))
# 3
take拿
sum(myList[:2])
or或者
myList[0] + myList[1]
and put it into "{approach}"并将其放入“{approach}”
getSum = lambda myList: {approach}
or或者
def getSum(myList):
return {approach}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.