使用Python做数值运算,python数值运算,#!/usr/bin/p
使用Python做数值运算,python数值运算,#!/usr/bin/p
#!/usr/bin/python# Some calculations. Note the lack of semicolons. Statements end at the end# of the line. Also, variables need not start with a special symbol as in# perl and some other Unix-bred languages.fred = 18barney = FRED = 44; # python 是大小写敏感的bill = (fred + barney * FRED - 10)alice = 10 + bill / 100 # Integer division truncatesfrank = 10 + float(bill) / 100print "fred = ", fredprint "bill = ", billprint "alice = ", aliceprint "frank = ", frank print# Each variable on the left is assigned the corresponding value on the right.fred, alice, frank = 2*alice, fred - 1, bill + frankprint "fred = ", fredprint "alice = ", aliceprint "frank = ", frank print# Exchange w/o a temp.fred, alice = alice, fredprint "fred = ", fredprint "alice = ", aliceprint# Python allows lines to be continued by putting a backslash at the end of# the first part. fred = bill + alice + frank - \ barneyprint "fred =", fredprint# The compiler will also combine lines when the line break in contained# in a grouping pair, such as parens.joe = 3 * (fred + bill - alice)print "joe =", fred
注意:
python做除法,默认是整除,会舍弃余数部分。当做除法的除数或者被除数有一个是float类型时会做小数除法python的print后面是元组时会自动在各个元素之间加空格,每个print语句都会换行一个语句可以同时给多个变量赋值,变量赋值的顺序是从右向左依次赋值fred, alice = alice, fred
语句可以用来交换fred和alice变量的值,但不需要临时变量相关内容
- Python 使用字符串,python使用字符串,如下代码演示Pyth
- python String (二),pythonstring,#!/usr/bin/p
- 用Python读写XML文件,Python读写XML文件,以前用Python中的
- python String (三) 字符串运算,pythonstring,#!/usr/bin/p
- python使用py2exe打包PyQt程序要点,py2exepyqt,使用png格式作
- python使用HTMLParser解析html,pythonhtmlparser,一个Python HTM
- Python list使用示例,pythonlist示例,#!/usr/bin/p
- python if 语句,pythonif,#!/usr/bin/p
- python while语句,pythonwhile,python while
- Python使用cx_Oracle将oracle数据表中的数据导出成csv,cx_
评论关闭