循序渐进学Python2变量与输入

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

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

目录

 [隐藏

[编辑]注释

#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.
原文地址:https://www.cnblogs.com/elesos/p/6738322.html