Python开发
全局变量
a = 1
def f1():
global a
print a
import
多线程
thread = Thread()
thread.start()
thread.join()
判断Python输入是否为数字
在接收raw_input方法后,判断接收到的字符串是否为数字
例如:
str = raw_input(“please input the number:”)
if str.isdigit():
为True表示输入的所有字符都是数字,否则,不是全部为数字
str为字符串 str.isalnum() 所有字符都是数字或者字母 str.isalpha() 所有字符都是字母 str.isdigit() 所有字符都是数字 str.islower() 所有字符都是小写 str.isupper() 所有字符都是大写 str.istitle() 所有单词都是首字母大写,像标题 str.isspace() 所有字符都是空白字符、\t、\n、\r
获取变量类型
a = 1 b = [1,2,3,4] c = (1,2,3,4) d = {‘a‘:1,‘b‘:2,‘c‘:3} e = “abc” if isinstance(a,int): print “a is int” else: print “a is not int” if isinstance(b,list): print “b is list” else: print “b is not list” if isinstance(c,tuple): print “c is tuple” else: print “c is not tuple” if isinstance(d,dict): print “d is dict” else: print “d is not dict” if isinstance(e,str): print “d is str” else: print “d is not str”