##### chapter0
ctrl+shift+p 输入python:select interpreter 选择python解释器
多行注释
""" """ or ''' '''
print 打印
print("""
Python is powerful... and fast;
plays well with others;
runs everywhere;
is friendly & easy to learn;
is Open.
""")
print("hello,world")# output 输出, print 打印
####### chapter1
基础的控制台输出 Basic Console Output
##print()默认每次输入后会换行(等价于按了一次回车,或者 \n)默认每次输入后会换行(等价于按了一次回车,或者 \n)
print("Data",end="\n")
#转义字符\n \t ...
print("Data","whale",sep="")
##字符串 默认是空格分隔
print("p2s"*2,"data"*3, sep="/"*4)
print("Data"+"whale"+"P2S")##可进行加减乘运算
f-strings
x = 1
y = 2
print(f"一个简单的数学问题:\"{x} + {y} = ?\",答案是 {x+y}!")
from ipywidgets import interact
import ipywidgets as widgets
def f(x, y):
print(f"A simple math question: \"{x} + {y} = ?\", the answer is {x + y}!")
interact(f,x=1, y=2)
基础的控制台输入 Basic Console Input
input()
##可以接收 Console 的输入,并以字符串!!的形式返回,
可以给定个字符串参数,它会先输出到 Console,再接收输入
name = input("输入你的名字:")
print("あなたの名前は", name, "です")
类型转换
x= input("输入一个数字")
x = int(x) float(x)
x = int(input("输入一个数字:")) # f(g(x))
print(x, "的一半等于", x/2)
一行多个输入值
##在结尾加上 split(),默认分隔参数是空格,可以更改,如:split(",")
1 -> a,2 -> b
a, b = input().split(" ")
print(f"a = {a}, b = {b}")##赋值
导入模块“库”(Library)
##用 import 来导入,并且使用 xx.yy的方式来调用
import math # 使用库前先导入 Python 内置数学库 math 为例
print(math.factorial(5))### 阶乘 factorial
print(math.e)# Euler 常数
print(math.tau)##2pi
math.gcd(12, 36)# gcd 最大公约数2
def f(x):
a = x*(math.pi/180)
print(math.sin(a))
interact(f,x=30)### ≠0.5 0.1+0.2≠0.3?? 无可避免的浮点误差
错误 Error
# 语法错误 Syntax Errors,不符合语法规范,代码根本没有开始运行
# “运行时”错误 Runtime Errors,代码在运行过程中出错,也就是常说的“崩溃”(Crash)
# 逻辑错误 Logical Errors,代码能够运行,且运行过程中没有出错,但是不是想要的结果