Python

Python PerlC Java

Python Python


Python

Python

Linux Python ,

$ 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

prompt_1.png [prompt_1.png]

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

#!/usr/bin/python

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

>>> list =["a", "b", "c"]
>>> 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

andexecnot
assertfinallyor
breakforpass
classfromprint
continueglobalraise
defifreturn
delimporttry
elifinwhile
elseiswith
exceptlambdayield

Python Python {} python

:

if True:
    print ("True")
else:
    print ("False")

#!/usr/bin/python
# -*- 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 #

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# test.py

#
print ("Hello, Python!")  #

Hello, Python!

name = "Runoob" # 

python ''' """

#!/usr/bin/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

print ,

#!/usr/bin/python
# -*- 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

Python2 Python3 print


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