Python编程快速上手-让繁琐工作自动化 — 读书与代码笔记

chapter1

最近在学习《Python编程快速上手-让繁琐工作自动化》一书,学习这种代码操作实践性比较强的工具书,最好的办法就是跟着书上的一些例子和习题敲代码观察效果,跟随书本的进度来一个个实现作者提出的问题,敲下每个小程序段并调试成功,记录下书本的关键点,并整理保存在项目文件夹方便日后查阅,将会让自己在学习的过程中感受到自己的进步,同时也有助于慢慢提高自己的代码风格构建和代码编写能力。

作者在每章最后设计的实践项目作业题很有总结性,也非常实用,每章都有留下一道大题并给出代码思路,让读者来实现,在此,将在之后系列文章中给出我的一些代码实例,以供参考。

代码IDE平台采用Pycharm2020community版本实现,因为设计了Python代码模板,故统一显示了Copyright,实际上大部分参考书上例题及代码版权为书籍作者AI Sweigart

# -*- coding:utf-8 -*-
# @FileName     :say_hello.py
# @Time         :2020/8/12 22:16
# @Author       :Wu Hongyi
# @Copyright    :Wu Hongyi
# File description:
'''
本文件为Python编程快速上手-让繁琐工作自动化一书的第一、二章示例练习代码片段
'''
# @version      :Version1.0
# Modification description:
'''

'''

# 类似开机欢迎程序,与用户进行简单互动
# This program says hello and asks for my name.
print("Hello world!")
print("What is your name?")     # ask for their name
myname = input()
print("It is good to meet you, " + myname)
print('The length of your name is :')
print(len(myname))
print('What is your age?')      # ask for their age
myage = input()
print('Your will be ' + str(int(myage) + 1) + ' in a year.')

# 虽然数字的字符串值被认为与整型值和浮点型值完全不同,但整型值可以与浮点型值相等
42 == '42'
42 == 42.0
42 == 0042.0000

# 就像在说话和写作中使用双重否定,可以嵌套not操作符,但不建议
not not not not True

# 布尔操作符的操作顺序:在所有算数和比较操作符求值后,Python先求值not操作符
# 然后是and操作符,然后是or操作符
# 整体看来优先级遵从:    算数运算 > 比较运算 > 逻辑运算 > 赋值运算
2 + 2 == 4 and not 2 + 2 == 5 and 2 * 2 == 2 + 2

# if-else 代码块示例
name = input("请输入您的姓名:")
password = input("请输入您的密码:")
if name == 'Mary':
    print("Hello Mary")
if password == 'swordfish':
    print('Access granted.')
else:
    print("Wrong password.")

# break的用处
while True:
    print('Please type your name.')
    name = input()
    if name == 'your name':
        break;
print('Thank you!')

# continue的用处
while True:
    print("Who are you?")
    name = input()
    if name != 'Joe':
        continue
    print("Hello, Joe. What is the password? (It is a fish.)")
    password = input()
    if password == 'swordfish':
        break
print('Access granted.')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值