笨办法学PYTHON3 习题01 第一个程序

笨办法学PYTHON3 习题01 第一个程序

上手根据习题直接撸代码也未尝不可,事后回过头来总结,我觉得写代码首先要看一下代码书写规范。
毕竟优雅永不过时

Python官方教程中编写代码规范的核心要点

好的让我们正式开始

  • 习题01:将上面的内容写到一个文件中,取名为 ex1.py。
    这个命名方式很重要,Python 文件最好以 .py 结尾。
# -*- coding: utf-8 -*-

	"""
    @lenrn Python the hard way ex1 :the first program
    @author:Aoli
    @create:2022-2-21
	"""

	print("Hello World!")
	print("Hello again")
	print("I like typing this.")
	print("This is fun.")
	print("Yah!Printing.")
	print("I'd much rather you 'not'.")
	print('I "said" do not touch this')
	

学习心得:注意代码最后两段中,引号与双引号的区别,当字数串中引号会出现歧义是可用单双引号进行区分

  • 运行效果:

Hello World!
Hello again
I like typing this.
This is fun.
Yah!Printing.
I’d much rather you ‘not’.
I “said” do not touch this

  • 附加题1.1 让你的脚本多打印一行
# 只需要在以上脚本末行添加一行即可
print("\n")
  • 附加题1.2 让你的脚本只打印一行
print("Hello World!",end = " ")
print("Hello again",end = " ")
print("I like typing this.",end = " ")
print("This is fun.",end = " ")
print("Yah!Printing.",end = " ")
print("I'd much rather you 'not'.",end = " ")
print('I "said" do not touch this',end = " ")
  • 运行效果:

Hello World! Hello again I like typing this. This is fun. Yah!Printing. I’d much rather you ‘not’. I “said” do not touch this

知识点 此处用到python内置参数print的内建方法将多段话直接打印成一行,更多相应的方法后面会慢慢学
,此处我们使用 end = " "将各段话隔开并拼接成一行字符串

  • 附加题1.3 在一行的起始位置放一个 ‘#’
    (octothorpe) 符号。它的作用是添加注释
    注释可以用来解释代码 提高代码的可读性.
    在测试代码时添加注释,可用用来组织执行.
    井号有很多的英文名字,例如:’octothorpe(八角帽)’,’pound(英镑符)’,
    ‘hash(电话的 # 键)’, ‘mesh(网)’ 等。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值