Python编译器
运行python
1 2 3 4 5
| python --version 或 python3 --version
python3 # 进入交互环境,打印python版本 >>> import sys >>> print(sys.version)
|
编辑工具
Visual Studio Code
PyCharm
编写文件及运行
编辑hello.py
python hello.py # 执行
注释
1 2 3 4 5 6 7 8 9 10
| """ hello boy
Version: 0.1 Author: Ricky Chen """
# hello world
print('hello')
|
变量
1 2 3 4 5 6 7 8 9 10 11 12 13
| a = 10 b = 10.23
print(a + b) # 20.23
c = 3 print(a / c) # 除法,3.3333333333333335 print(a % c) # 取余,1
d = 'hello, world' e = True
print(type(a)) # 打印变量类型
|
1 2 3 4 5 6 7 8 9 10 11 12
| """ 输入a,b,转换成正数 %d表示整数占位符,进行a+b
Author: Ricky """ a = int(input('a = ')) b = int(input('b = '))
print('%d + %d = %d' % (a, b, a + b)) # 10 + 3 = 13 print('%d / %d = %d' % (a, b, a / b)) # 10 / 3 = 3,本来输出浮点数的,但是被%d转化了 print('%d // %d = %d' % (a, b, a // b)) # 10 // 3 = 3
|
赋值运算符
1 2 3 4 5 6 7 8 9
| """ 复合赋值运算符 """ a = 5 b = 2 a += b # 等价 a = a + b print(a) # 7 a *= b # 等价 a = a * b print(a) # 14
|
up https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/02.%E8%AF%AD%E8%A8%80%E5%85%83%E7%B4%A0.md
原文链接: https://chenqiaorui.github.io/2023/05/18/第3期:Python学习/
版权声明: 转载请注明出处.