python中最好的方法是什么:if语句中有多个OR或IN?考虑性能和最佳实践.
if cond == '1' or cond == '2' or cond == '3' or cond == '4' (etc...) :
Run Code Online (Sandbox Code Playgroud)
要么
if cond in ['1','2','3','4']:
Run Code Online (Sandbox Code Playgroud)
谢谢.
理解这种行为有点难:
def a():
pass
type(a)
>> function
Run Code Online (Sandbox Code Playgroud)
如果type的a就是function,是什么type的function?
type(function)
>> NameError: name 'function' is not defined
Run Code Online (Sandbox Code Playgroud)
又为何type的type距离a是type?
type(type(a))
>> type
Run Code Online (Sandbox Code Playgroud)
最后一个:如果a是object,为什么我不能这样做:
isinstance(a, object)
>> True
class x(a):
pass
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
Run Code Online (Sandbox Code Playgroud)
谢谢!
我需要在Go中切一个字符串.有时我有拉丁字符,否则我有阿拉伯语字符,但阿拉伯语的[:1]返回不同的值.
package main
import "fmt"
func main() {
a := "a"
fmt.Println(a[:1]) // work
b := "?"
fmt.Println(b[:1]) // not work
fmt.Println(b[:2]) // work
fmt.Println(len(a) == len(b)) // false
}
Run Code Online (Sandbox Code Playgroud)