Python
Python PerlC Java
Python Python
Python
Python
Linux Python ,
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Windows Python
Python Enter
>>> print ("Hello, Python!")
Python 2.7.6 ,
Hello, Python!
Python Python .py test.py
print ("Hello, Python!")
Python PATH
$ python test.py
Hello, Python!
Python test.py
print ("Hello, Python!")
Python/usr/bin
$ chmod +x test.py # $ ./test.py
Hello, Python!
Python2.x Python3.x print
Python2.x Python3.x print __future__ Python2.x print Python3.x print
>>> print list # python2.x print
['a', 'b', 'c']
>>> from __future__ import print_function # __future__
>>> print list # Python2.x print
File "<stdin>", line 1
print list
^
SyntaxError: invalid syntax
>>> print (list) # Python3.x print
['a', 'b', 'c']
>>>
Python3.x Python2.x __future__
Python
Python
Python (_)
Python
_foo from xxx import *
__foo __foo__ Python __init__()
Python ;
>>> print ('hello');print ('runoob');
hello
runoob
Python
Python
Python
| and | exec | not |
| assert | finally | or |
| break | for | pass |
| class | from | |
| continue | global | raise |
| def | if | return |
| del | import | try |
| elif | in | while |
| else | is | with |
| except | lambda | yield |
Python Python {} python
:
print ("True")
else:
print ("False")
# -*- coding: UTF-8 -*-
# test.py
if True:
print ("Answer")
print ("True")
else:
print ("Answer")
#
print ("False")
File "test.py", line 11
print ("False")
^
IndentationError: unindent does not match any outer indentation level
IndentationError: unindent does not match any outer indentation level tab
IndentationError: unexpected indent , python "Hi tab " python
Python
,
Python
\
total = item_one + \
item_two + \
item_three
[], {} ()
days = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday']
Python
Python ( ' )( " )( ''' """ )
word = 'word' sentence = "" paragraph = """ """
Python
python #
# -*- coding: UTF-8 -*-
# test.py
#
print ("Hello, Python!") #
Hello, Python!
name = "Runoob" #
python ''' """
# -*- coding: UTF-8 -*-
# test.py
'''
'''
"""
"""
Python
PythonPython
#!/usr/bin/python
# -*- coding: UTF-8 -*-
raw_input(" enter ...\n")
\n enter()
Python(;)
#!/usr/bin/python import sys; x = 'runoob'; sys.stdout.write(x + '\n')
$ python test.py runoob
print ,
# -*- coding: UTF-8 -*-
x="a"
y="b"
#
print x
print y
print '---------'
#
print x,
print y,
#
print x,y
a b --------- a b a b
ifwhiledefclass( : )
(clause)
if expression : suite elif expression : suite else : suite
Python -h
$ python -h usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... Options and arguments (and corresponding environment variables): -c cmd : program passed in as string (terminates option list) -d : debug output from parser (also PYTHONDEBUG=x) -E : ignore environment variables (such as PYTHONPATH) -h : print this help message and exit [ etc. ]
Python Python
younger
129***[email protected]
sys test.py
sys.argv
,
sys.argv[0] sys.argv[1]
younger
129***[email protected]
qing
282***[email protected]
#!/usr/bin/python : /usr/bin python
#!/usr/bin/env python(: python /usr/bin env python
#!/usr/bin/python python;
#!/usr/bin/env python python ,
qing
282***[email protected]
TRER
234***[email protected]
Python
TRER
234***[email protected]