notes for p2s chapter 1

HydroOJ个人主页

教程

slides/chapter_1

任务

启航,Python基础

学习时间

5/13

笔记

hello, world

相比于C,python第一行代码简单多了

print("hello world")

//print的名字来自历史上的打孔计算机

hello world,检测运行环境的简单手段
Brian Wilson Kernighan,C语言之父
最初的hello world C代码,没有#include和return 0

注释

单行注释,#开头
多行注释,‘’’ or “”"包裹起来
//# magic comment会被当作代码处理
程序员讨厌别人的代码不写注释,也讨厌给自己的代码写注释

BASIC CONSOLE OUTPUT

编程中的函数类似数学上的函数

print("Datawhale")# 将填入的内容显示在Consolde,默认换行
print("Datawhale", end="")

print("Data", "whale")# 也可以一次输出多个内容,默认以空格分隔
print("Data", "whale", sep="*")

print("Data"+"whale"+"!!"*2)
# Datawhale!!!!

print(f"a easy problem:\"{x} + {y} = ?\",答案是 {x+y}!")
# f-strings, amazing function
# use f"..." and {...}

# print many lines at one time
print("""
hell
o, w
orld
""")

//python确实是可以对字符串方便操作,当初学C反而不习惯

错误ERROR

  • 语法错误Syntax Errors
  • 运行时错误Runtime Errors(Crash)
  • 逻辑错误Logical Errors

BASIC CONSOLE INPUT

name = input("输入你的名字:")
print("あなたの名前は", name, "です")
# python uses Unicode, support any character
# amazing
# 自己实践,发现vscode输出乱码,不支持UTF8,新建了一个系统环境变量,成功了

//一文完美解决vscode python输出中文乱码问题

x = int(input("输入一个数字"))
print(x, "的一半等于", x/2)

# input more than one variable in one line
a, b = input().split(",")
print(f"a = {a}, b = {b}")

库Library

import math# import a library before using it!
print(math.factorial(20))
print(math.e)
math.gcd(12, 36)

课后思考

0.1+0.2≠0.3?? 无可避免的浮点误差:https://www.bilibili.com/video/BV1xq4y1D7Ep

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值