Learn Python The Hard Way 3: Ex01 A good first Program
来源:互联网 发布:网络媒介论文 编辑:程序博客网 时间:2024/06/07 00:55
3 Ex01 A good first program
3.1 First program
开始第一个有代码的学习,再次强调 Do not copy! Typing!
# -*- coding: utf-8 -*-print "Hello World!" #这里是注释.print "Hello Again." #没有分号(;)结尾,分隔语句.print "I like typing this."print "This is fun."print "Ya! Printing."print "I'd much rather you 'not'."print 'I "said" do not touch this.'
# -*- coding: utf-8 -*-
这条语句表示我们需要使用Unicode UTF-8, 在编辑时输入中文会导致ASCII码错误,所以我们需要告诉Python, 我们需要使用Unicode UTF-8.
如果你输入代码没有错误,你将看到这样的输出:
3.2 错误处理
当然, 不是每次输入的代码都会是正确的, 如果遇到了错误:
$ python ex/ex1.py File "ex/ex1.py", line 3 print "I like typing this. ^SyntaxError: EOL while scanning string literal
- python解释器告诉我们错误的python源文件是ex1.py .
- 错误的地方在第三行 line 3.
- 同时解释器给出了确切的错误位置, 注意那个箭头!!! 他指给你这里错了! 这里是少了一个双引号.
- SyntaxError: EOL while scanning string literal. 这是错误类型,这里是语法错误.
3.3 问题探索
下面给出三个任务, 请自主探索, 如果做不到请学习后面章节.
1. 让你的程序打印一点好玩的东西, 比如: ❤
2. 让程序只在一行内打印.
3. 为什么要在程序开始放置一个#? 这个字符的作用是什么?
# -*- coding: utf-8 -*-#问题探索1print " *** *** "print " ********* *********"print "************ ************"print "************* *************"print "************** **************"print "*************** ***************"print " ******* *** *** *******"print " ****** ***** ******"print " ****** *** ******"print " ****** * ******"print " ****** * ******"print " **************"print " **********"print " ******"print " ***"print " *"
# -*- coding: utf-8 -*-#问题探索2print "Hello World!", #在语句结尾加了逗号.print "Hello Again.",print "I like typing this.",print "This is fun.",print "Yay! Printing.",print "I'd much rather you 'not'.",print 'I "said" do not touch this.',
# -*- coding: utf-8 -*-#问题探索3#号是注释后面一行内容.print "Hello Python!"
0 0
- Learn Python The Hard Way 3: Ex01 A good first Program
- 学《learn python the hard way》(3)
- Learn Python The Hard Way
- Learn Python The Hard Way
- 《Learn Python The Hard Way, 3rd Edition》
- Learn Python The Hard Way 3: Ex0 Setup
- Learn Python the Hard Way ex48
- learn python the hard way 的ex48
- Learn Python The Hard Way-Ecercise1~5
- Learn Python The Hard Way-Ecercise6~10
- Learn Python The Hard Way-Ecercise11~15
- Learn Python The Hard Way-Ecercise16~20
- Learn Python The Hard Way-Ecercise21~25
- Learn Python The Hard Way-Ecercise26~30
- Learn Python The Hard Way-Ecercise31~35
- Learn Python The Hard Way-Ecercise36~40
- Learn Python The Hard Way exercise 42
- Learn Python The Hard Way Ex40翻译
- 升级CentOS6.5安装镜像中的Linux内核版本
- 使用handler来实现计时操作
- .NET程序开发运行框架
- interleaving String
- 【Nginx】双代理以及复杂条件的rewrite跳转
- Learn Python The Hard Way 3: Ex01 A good first Program
- Ubuntu14.04下支持GTX1070 GPU加速Tensorflow环境配置
- VoLTE直接承载语音解决方案
- [NOIP模拟][LIS][数列映射][最短路][数论+图论][矩阵乘法][容斥原理]
- 网络工程师学习之路
- Java系列(三)__Java面向对象(1)
- 心情11/15
- 遍历Map的四种方法
- ssprintf sscanf atoi itoa 整数字符串转换