您的位置:首页 > 编程语言 > Python开发

循序渐进学Python2变量与输入

2017-04-20 13:36 330 查看
新建一个test.py文件,右键选择“Edit with IDLE”,编辑完成后,Ctrl+S保存,然后按下F5就可以执行代码了。

注:IDLE是Python官方提供的一个IDE工具。

目录

 [隐藏
1 注释
2 数字
3 变量
4 输入用法


[编辑]注释

#This is a comment

print"This will run."#comment


多行注释使用三个单引号(''')或三个双引号(""")。


[编辑]数字

print 25 + 30 / 6

print"Is it true that 3+2 < 5-7?"

print 3+2<5-7


输出:

30
Is it true that 3+2<5-7?
False



[编辑]变量

cars =100

print"There are", cars,"cars available."


输出:
There are 100 cars available.


my_name ="Lei Jun"
your_name ="Jobs"

print"Let's talk about", my_name
print"Let's talk about %s and %s." % (my_name, your_name)


输出:
Let's talk about Lei Jun
Let's talk about Lei Jun and Jobs.


[编辑]输入用法

print"How old are you?"
age =raw_input()

print"You're %s old."% age


输出:
How old are you?
27
You're 27 old.




age =raw_input("How old are you?")

print"You're %s old."% age


输出:
How old are you?38
You're 38 old.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: