selenium学习之路2

1: 学习Python时:按文档练习print报错

>>> print "hello"
  File "<stdin>", line 1
    print "hello"
                ^
SyntaxError: Missing parentheses in call to 'print'
>>> name = "zhangsan"
>>> print "hello %s,Nice to meet you!" %name
  File "<stdin>", line 1
    print "hello %s,Nice to meet you!" %name
                                     ^
SyntaxError: Missing parentheses in call to 'print' 

解决方法:http://blog.csdn.net/dracotianlong/article/details/48607593  :python2系列可以支持 print “xxxx” ,python3系列需要使用print("xxx")
>>> print("hello")
hello

2:有了之前的经验,在练习

>>> name = "zhangsan"

>>> print "hello %s ,Nice to meet you!" %name时,我知道要加上括号:

>>> print("hello %s , nice to meet you!") %name
hello %s , nice to meet you!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'居然还是报错了,不能识别后面的%,

 

解决方法:http://www.cnblogs.com/hwd9654/p/5676746.html  :后来才发现,python3.x与python2.x有一点区别,
原来%(变量名,...)应该是加在print括号里的
如:print("who is the murder? %s or %s" % (a, b))

所以:>>> print("hello %s , nice to meet you!" %name)
hello zhangsan , nice to meet you!

 

posted on 2017-06-23 23:17  张&娟  阅读(92)  评论(0编辑  收藏  举报

导航