Răsfoiți Sursa

date 1 注释,数据类型,变量

tanlie 1 săptămână în urmă
părinte
comite
2deba1e38c
3 a modificat fișierele cu 59 adăugiri și 0 ștergeri
  1. 18 0
      day01/example02.py
  2. 16 0
      day01/example03.py
  3. 25 0
      day01/example04.py

+ 18 - 0
day01/example02.py

@@ -0,0 +1,18 @@
+"""
+example02 - 数据类型
+author: tanlie
+date: 2026/8/20
+"""
+
+print(100)   # integer  100
+print(0b100) # binary 二进制 4
+print(0o100) # octal 八进制 64
+print(0x100) # hexadecimal 十六进制 256
+
+print(3.14)  # float 浮点数 3.14
+print(3.14e2) # scientific notation 科学计数法 314.0
+
+print("hello python") # string 字符串
+
+print(True)  # boolean 布尔值 True
+print(False) # boolean 布尔值 False

+ 16 - 0
day01/example03.py

@@ -0,0 +1,16 @@
+"""
+example03 - 变量的定义和使用
+命名规则:
+1. 变量名只能包含字母、数字和下划线,且不能以数字开头。
+2. 变量名不能使用Python的关键字。
+3. python 是变量大小写敏感的语言,变量名 a 和 A 是不同的变量。
+auther: tanlie
+date: 2026/8/20
+"""
+
+a = 45
+b = 12
+print(a + b) # 57
+print(a - b) # 33
+print(a * b) # 540
+print(a / b) # 3.75

+ 25 - 0
day01/example04.py

@@ -0,0 +1,25 @@
+"""
+example04 - 使用type函数检查变量的类型
+auther: tanlie
+date: 2026/8/20
+"""
+
+
+a = 45
+b = 3.14
+c = "123.45"
+d = True
+
+print(type(a)) # <class 'int'>
+print(type(b)) # <class 'float'>
+print(type(c)) # <class 'str'>
+print(type(d)) # <class 'bool'>
+
+print(str(a)) # 45
+print(int(b)) # 3
+print(float(c)) # 123.45
+print(int(d)) # 1
+print(int(False)) # 0
+
+print(ord('檀')) # 27264
+print(chr(65)) # A