1. 基础语法
第一行代码
print("hello world!")
数据类型
- 整数和浮点数
print(type(1000)) # <class 'int'>
print(type(1_000)) # <class 'int'>
print(type(1000.0)) # <class 'float'>
print(type(1e3)) # <class 'float'>
- 字符串
print('1000')
print(type('1000')) # <class 'str'>
- 布尔型
print(True, False)
print(type(True), type(False)) # <class 'bool'> <class 'bool'>
变量和赋值
- python 中不需要显式定义数据类型
a = 1
b = 2.0
c = '3'
d = True
print(a,b,c,d)
运算
- 数值运算
a = 1
b = 2
p = a + b
q = a - b
r = a * b
s = a / b
print(p,q