美文网首页
ex01.第一个程序

ex01.第一个程序

作者: 李有锐 | 来源:发表于2019-02-03 23:38 被阅读6次

1. 环境介绍

我使用的环境是windows/notepad++/Python 3.7.2

2. 代码

# coding:utf-8
print("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')

3.输出

ex01输出.png

4.附加练习

4.1. 让你的脚本再多打印一行

# coding:utf-8
print("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')
print('再多打印一行')     # 新增

4.2. 让你的脚本只打印一行

print("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')
# print('再多打印一行')     # 新增

5.总结

这是《learn PYTHON the HARD WAY(3rd)》中第一个习题。主要介绍了print()这个函数的用法。
我手里的版本还是print,我将它根据python3的特性进行了“翻译”
代码很短,也很简单。这里有一些需要注意的点:

  1. print()括号中跟需要输出的内容,内容可以是变量、可以是任何形式的数据结构,但本习题中针对字符串(str:在Python中字符串的数据类型是列表);
  2. 字符串的特点是可以使用双引号“”,也可以使用单引号‘’。但一定要成对出现,且不能交叉配对;
  3. 习题中第一行# coding:utf-8是代码字符集格式声明,作用就是当使用其他字符集格式进行录入的,可以在解释器中强制使用utf-8字符集进行运行。

相关文章

网友评论

      本文标题:ex01.第一个程序

      本文链接:https://www.haomeiwen.com/subject/ssbusqtx.html