python学习日志

  • 格式:txt
  • 大小:13.26 KB
  • 文档页数:5
>>> if age >=18
SyntaxError: invalid syntax
>>> if age >=18:
print 'adult'
else:
print 'teenager'
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
I'm learning
Python.
>>> print '\\\n\\'
\
\
>>> print '\\\t\\'
\ \
>>> print r'\\\t\\'
\\\t\\
>>> print '''line1
... line2
... line3'''
line1
... line2
File "<pyshell#106>", line 1, in <module>
'hi, $s, you have $%d.' %('Michael',1000000)
TypeError: %d format: a number is required, not str
>>> 'hi, %s, you have $%d.' %('Michael',1000000)
... line3
>>> print '''line1
line2
line3'''
line1
line2
line3
>>> print r'''line1
line2
line3'''
line1
line2
line3
>>> print r'''''line1
line2'''''
''line1
>>> name=raw_input()
print "hello,",name
>>> c:\workspace>python hello.py
SyntaxError: invalid syntax
>>> name=raw_input()
limin
>>> name
'limin'
>>> print name
65
>>> chr('65')
Traceback (most recent call last):
File "<pyshell#80>", line 1, in <module>
chr('65')
TypeError: an integer is required
>>> chr(65)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 3: invalid start byte
>>> 'xe4\xb8\xad\xe6\x96\x87'.decode('utf-8')
Traceback (most recent call last):
u'\u4e2d\u6587'
>>> print '\xe4\xb8\xad\xe6\x96\x87'.decode('utf-8)
SyntaxError: EOL while scanning string literal
>>> print '\xe4\xb8\xad\xe6\x96\x87'.decode('utf-8')
Ture or False
NameError: name 'Ture' is not defined
>>> True or False
True
>>> not True
False
>>> not False
True
>>> if age>=18
SyntaxError: invalid syntax
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print "hello,world"
File "<pyshell#75>", line 1, in <module>
PI
NameError: name 'PI' is not defined
>>> 10/3
3
>>> 10.0/3
3.3333333333333335
>>> 10%3
1
>>> ord('A')
hello,world
>>> print "thequcik brown fox","jumps over","the lazy dog"
thequcik brown fox jumps over the lazy dog
>>> print "the qucik brown fox","jumps over","the lazy dog"
line2
>>> True
True
>>> false
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
false
NameError: name 'false' is not defined
u'\u4e2d'
>>> u'abc'.encode('utf-8')
'abc'
>>> u'中文'.encode('utf-8')
'\xe4\xb8\xad\xe6\x96\x87'
>>> len(u'abc')
3
>>> len(u'ABC')
3
>>> len('ABC')
3
>>> len(u'中文’)
'A'
>>> print u'中文'
中文
>>> u
Traceback (most recent call last):
File "<pyshell#83>", line 1, in <module>
u
NameError: name 'u' is not defined
>>> u'中'
>>> a='XYZ‘
SyntaxError: EOL while scanning string literal
>>> a='ABC'
>>> b=a
>>> a='XYZ'
>>> print b
ABC
>>> PI
Traceback (most recent call last):
limin
>>> print "I'm OK"
I'm OK
>>> print "I'm "OK"!"
SyntaxError: invalid syntax
>>> print "I\'m\"ok\"!"

下载文档原格式

  / 5