python 输出语句;
print() 格式化对xxxxx输出:
print(format(xxxxx val.fatmat_modiffer))
其中:
format为关键字。
val 输出占位数。
fatmat_modiffer 输出精度。
In [1]: print(format(12.34567))
12.34567
In [2]: print(format(12.34567,'9.2f'))
12.35
In [3]: print(format(12.34567,'9.10f'))
12.3456700000
In [4]: print(format(12.34567,'3.2f'))
12.35
In [5]:
__________________________________________________
python 输入:
raw_input()
用raw_input() 得到的输入是字符串
例:
In [7]: age=raw_input("Enter your age: ")
Enter your age: 23
In [8]: type(age)
Out[8]: str
In [9]: int(age)【这里这样转是不行的,一定要变量转出去】
Out[9]: 23
In [10]: type(age)
Out[10]: str
In [11]: age=int(age)
In [12]: type(age)
Out[12]: int
In [13]: age=int(raw_input("Enter your age: "))
Enter your age: 25
In [14]: type(age)
Out[14]: int
In [15]: age2=int(raw_input("Enter your age: "))
Enter your age: 2
In [16]: type(age2)
Out[16]: int
In [17]:
float 可以转换浮点数。
In [17]: age3=raw_input("Enter your age: ")
Enter your age: 1.234
In [18]: type(age3)
Out[18]: str
In [20]: agee=float(raw_input("Enter your age: "))
Enter your age: 1.234
In [21]: type(agee)
Out[21]: float
___________________________________________________