【Python初学者】准备

本文记录了作者初次接触Python编程的学习过程,包括环境搭建、编辑器选择及基础语法实践等内容。

准备着手学习Python这门久仰大名的语言。本篇随笔是学习它的准备阶段。

操作系统:

Mac OS 10.11.5

下载编辑器Testwrangler

点我

第一个Python程序

在命令行中运行python:
885822-20160919185516262-1534282408.png

在命令行中新建文件夹ChenPython,并且在其中新建文件 MyFirstPythonProgram
885822-20160919191109184-1660758830.png

换名字,改成.py格式;然后编辑它,在终端运行:python MyFirstPythonProgram.py
885822-20160919191822012-998978266.png

井号的作用

在python中,#是注释的意思。

#Python examples 2016/9/19 by wasdns
print "HelloWorld!"
#End of file

#的英文名是pound character。

简单计算

#Python Examples 2016/9/19 by Wasdns
print "Calculator:" 30 + 25 / 5
print "Calculator:" 30 % 5
#End of file

哈哈,首错:
885822-20160919192948746-1297468324.png

更改:

#Python Examples 2016/9/19 by Wasdns
print "Calculator:", 30 + 25 / 5
print "Calculator:", 30 % 5
#End of file

输出结果:
885822-20160919193116949-531313582.png

增加大小比较:

#Python Examples 2016/9/19 by Wasdns
print "Calculator:", 30 + 25 / 5
print "Calculator:", 30 % 5

print "Pause..."

print "It's it true? 3 + 3 < 9", 3 + 3 < 9
print "Did the Terminal print true?"
#End of file

输出:
885822-20160919193505434-1720257447.png

变量

#Python Examples 2016/9/19 by Wasdns
print "Calculator:", 30 + 25 / 5
print "Calculator:", 30 % 5

print "Pause..."

print "It's it true? 3 + 3 < 9", 3 + 3 < 9
print "Did the Terminal print true?"

print "Add a variable..."

Iamboy = 1
Sheisgirl = 1
Iamgirl = 0
Sheisboy = 0

print "Iamboy = ", Iamboy, " Sheisgirl = ", Sheisgirl, " Iamgirl = ", Iamgirl, " Sheisboy = ", Sheisboy

print "Add Finished..."

#End of file

输出:
885822-20160919194424652-590583027.png

2016/9/19

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值