1.shell交互式
python 在窗口中打印
(1)打印字符串
>>> print "Hello,python!"
Hello,python!
(2)字符串相加
>>> print( "well water" + "river" )
>>> print "well water" + "river"
well waterriver
>>> print( "well water" + "river" + "\n" )*8 乘以8,即打印8次
well waterriver
well waterriver
well waterriver
well waterriver
well waterriver
well waterriver
well waterriver
well waterriver
【课后题】print( "well water" + "river" + "\n" )+8为什么报错?
(3)四则运算
>>> print(5+3)
8
>>> 5+3
8
>>> 123456789 * 987654321
121932631112635269
2.脚本
#coding:utf-8 #支持中文
print "...鱼C工作室...";
temp = input("temp = ") #input函数:接受用户的输入,赋值给
guess = int(temp) # 强制转换
if guess == 8: #注意:有冒号
print("正确\n")
else:
print("错误\n")
print("游戏结束\n")
执行命令:
python test.py 或者 test.py
3.python中的内建函数(BIF) http://blog.youkuaiyun.com/qq_20545159/article/details/46334323
gjw@gjw:~/TEST_PYTHON$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>>