python笔记-1

上一篇 / 下一篇  2012-05-23 13:01:00 / 个人分类:Python笔记

1、从终端输入一个数字(input):
f = input("Enter number here:")

2、3次方(**)
5 ** 4 = 625

3、绝对值(abs)
abs(-18) = 18

4、使用数学函数(math)
import math
math.floor(18.7) = 18.0
math.sqrt(81) = 9.0
bucky = math.sqrt
bucky(9) = 3.0

5、输入字母(raw_input)
x = raw_input("Enter name: ")

6、'' == ""
这两个符号一样

7、""与''内嵌
"he's a jerk"   ---->"he's a jerk"
'he\'s a jerk'  ---->"he's a jerk" 

8、a = "bucky"
b = "boberts"
a,b    ----->('bucky','boberts')

9、数字和字符串
数字和字符串不能够直接相加,使用str()将数字转化为字符串
num = str(18)
print "bucky is "+num   ——>bucky is 18

10、``使用
num2 = 32
print "my mom is " + `num2`   --->my mom is 32


TAG: Python python

 

评分:0

我来说两句

Open Toolbar