》》》》》以上论述是针对python2.x版本,在python3.x中,只保留了input,且其输出结果都是字符串《《《《《《《《
以下是python3.x的实例:
#testName.py def func1(): print("my name is testName ,func1") # xiaoming_age = int(input("输入年龄:")) xiaoming_age = input("输入年龄:") return xiaoming_age def func2(x): xiaoming_age = 16 if(xiaoming_age==x): return '有' else: return '没有' if __name__ == "__main__": x = func1() print('%s具有类型转换功能'%func2(x))2.转化输入 使用raw_input()函数获得用户的age,接着用float()把age转换成浮点数。 >>> age = raw_input() 90 >>> age '90' >>> age = float(age) >>> age 90.0 >>> age = int(age) >>> age 90 3.格式化输出 3.1 >>> greeting = "good {},{},how are you?" >>> time = 'morning' >>> name = 'heres' >>> print greeting.format(time,name) good morning,heres,how are you? 3.2 >>> line = 'hello,{0},{1}' >>> print line.format('wang','zuan')
hello,wang,zuan
3.3
>>> str = input("输入名字:")输入名字:heres>>> print('我的名字叫%s'%str)我的名字叫heres
