@yanglt7
2018-11-14T03:21:09.000000Z
字数 1312
阅读 671
Python
(1)运行 python:命令提示符-输入 python。
C:\Users\Hope92>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
(2)在交互式环境的提示符>>>下,直接输入代码,按回车,就可以立刻得到代码执行结果。
>>> 1+1
2
>>>
(3)输出字符串,输入 print(),用单引号或双引号把字符串括起来,但是单引号和双引号不能混用。
>>> print('Hello,world')
Hello,world
>>>
(4)退出 python:输入 exit()。
>>> exit()
C:\Users\Hope92>
(5)保存python文件只能以 .py 为后缀,文件名只能是英文字母、数字和下划线组合。绝对不能用 Word 和记事本保存。
(6)在命令提示符输入 py 文件所在目录即可运行程序。
(7)用文本编辑器如 Sublime 时,print 前面不能有空格。
(8)print函数可接受多个字符串,遇到逗号会输出一个空格。
>>> print('The quick brown fox','jumps over','the lazy dog')
The quick brown fox jumps over the lazy dog
>>>
(1)print('字符串')
>>> print('word')
word
>>>
(2)print('字符串1','字符串2','字符串n')
>>> print('word1','word2','word3')
word1 word2 word3
>>>
(3)打印整数,print(300),或计算结果 print(100+200)
>>> print(300)
300
>>> print(100+200)
300
>>>
(4)打印字符串和结果
>>> print('100 + 200 =',100+200)
100 + 200 = 300
>>>
(1)输入name = input() - 回车 - Tom ,查看变量,输入 name
>>> name = input()
Tom
>>> name
'Tom'
>>>
这里,name是一个变量
(2)打印变量内容,print(name)
>>> name = input()
Tom
>>> print(name)
Tom
>>>
(3)新建 .py 文件 name=input() print('hello,',name) 在命令行运行程序
C:\Users\Hope105>F:/Personal/ylt/python/input.py
Tom
hello, Tom
或name=input('please enter your name') print('hello,',name) 在命令行运行程序
C:\Users\Hope105>F:/Personal/ylt/python/input.py
please enter your nameTom
hello, Tom