如何解决功能问题,同时允许它是动态的? [英] How to fix the function issue while allowing it to be dynamic?

查看:104
本文介绍了如何解决功能问题,同时允许它是动态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数(char1,char2,char3,char4,Number) )

前四项代表 chars 最后一个是 int ,我可能会添加更多的字符,所以函数不能是静态的。主函数将开始像

  def函数(* args):
table_line =
for x在范围内(数字/ 2):

但是通过赋予函数args它不再知道它应使用第三行提供的参数号。

解决方案

传递数字作为第一个参数:

  def func(number,* char):
...


Let's say i'm calling a function given the following arguments

Function(char1, char2, char3, char4, Number)

where the first 4 terms represent chars and the last is an int, i might add more chars so the function can't be static . The main function will start like

def Function(*args):
  table_line = ""
  for x in range(Number/2): 

but by giving the Function args it no longer knows that it should use the supplied argument number in that third line.

解决方案

Pass number as the first argument:

def func(number, *char):
    ...

这篇关于如何解决功能问题,同时允许它是动态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆