1. print 输出
>>> :主提示符,表示解释器在等你输入下一个语句
... :次提示符,表示解释器在提示你它在等你输入下一个字符。
%s,%d, %f等,分别是用字符串,整数,浮点数替换。
>>> myString = "Hello World"
>>>
>>> print myString
Hello World
>>>
>>> myString
'Hello World'
>>>
>>>
>>> print "%s is a beautiful girl , she's %d ." % ("Lucy",21)
Lucy is a beautiful girl , she's 21 .
>>>
其中,print "%s is a beautiful girl , she's %d ." 和C语言中的printf() 函数很相似,从Python与C语言的关系不难看到两者的相似之处。
>>> yes = "YES"
>>> no = "NO"
>>>
>>> print "I say ", yes,"u say ",no
I say YES u say NO
>>>
>>> print "I say %s , u say %s" % (yes*3,no*3)
I say YESYESYES , u say NONONO
>>>
带有两个参数的print :
strArray = ["hello","my","name","is","fulairy"]
for s in strArray:
print(s,len(s))
结果输出:
/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 /Users/apple/project/PycharmProjects/untitled/python_demo/fibonacci.py
('hello', 5)
('my', 2)
('name', 4)
('is', 2)
('fulairy', 7)
Process finished with exit code 0
2.
(1)raw_input()内建函数,
该函数接收用户标准输入,然后赋值给变量。 下面的输入信息赋值给了变量pyStr 从hello ---->world
>>> pyStr = raw_input("hello")
helloworld
>>> pyStr
'world'
>>>
(2) 使用in()函数 : 将数值字符串转换成整数值
>>> testInt = 0
>>> print testInt
0
>>> testInt = int("2222")
>>> testInt
2222
>>>
3. 其他
1)注释: Python中的注释使用 #号,也支持和java里面的文档注释,但是用的少
2)运算符:
+ - * / // **
注意: / // 两个都是除法运算符,//表示浮点除法 ** 表示乘方运算
< <= > >= !=<>
注意: 3<4<5 可以理解为: 3<4 and 4<5
逻辑运算符: and or not 且,或,非
3)变量名: 以大写或者小写字母开头,或者下划线开头,其余可以是数字,字母,下划线等
4)五种基本数据类型:
int long bool(TRUE---非0,FALSE---0) float complex (复合类型)
注意: 还有一种数据类型,decimal :