这是我的问题我定义了许多函数,我想循环遍历这些函数的列表,并以正确的顺序一次运行一个.
def one():
print "One "
def two():
print "Two "
def three(): "Three "
print "Three "
arr = ('one','two','three')
for fnc in arr:
<some how run the function name in the variable fnc>
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助,因为我是python和django的初学者.
我正在使用python,我只是想知道是否可以将变量名存储在另一个列表中.
Achievement = ['hi', 'hey', 'hello']
lines = ['Achievement', 'hi']
print lines[0][2]
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我希望输出为'hello'.任何人都可以建议我实现这一目标.
有没有办法评估比较运算符作为字符串传递的比较。没有做很多if-else的。铁
def cmp(arg1, op, arg2) : ......
Run Code Online (Sandbox Code Playgroud)
进而 :
cmp(5, "==", 6)
cmp(7, ">", 6)
cmp(12, "<=", 34)
cmp("abc", "==", "bad")
Run Code Online (Sandbox Code Playgroud) 我有一个表示函数的字符串,比如"x * (x - 32 ( 2 /x) )"
.我正在使用matplotlib
,但我不知道如何将此字符串转换为绘图点数组.
我想从用户输入调用一个函数,但在括号中包含参数.例如,如果我有一个带有一个参数的函数:
def var(value):
print(value)
Run Code Online (Sandbox Code Playgroud)
我想问用户一个命令和参数,然后用参数调用该函数:
Input Command: var("Test")
Test
Run Code Online (Sandbox Code Playgroud) 如何'
从字符串中删除'/'
并将其用于Python中的除法?
例如:
a='/'
b=6
c=3
bac
Run Code Online (Sandbox Code Playgroud)
答案应该是2.
我有一些尺寸以英寸格式输入为文本,例如:text =“ 20 7/8 16 1/4”#前两个表示长度,后两个表示宽度我可以更改此字符串使用text.split()转换为字符串列表以获取:[“ 20”,“ 7/8”,“ 16”,“ 1/4”]。
现在,我想将前两个项目20 + 7/8相加得到20.875。如何将7/8转换为浮点数?