Files
task-3-2-1-Text-Processing-…/cxy.py
2026-04-21 11:26:35 +08:00

31 lines
740 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#第一题
str1 = "Hello"
str2 = 'Hello'
print("双引号表示:", str1)
print("单引号表示:", str2)
print("两种表示方式是否相同:", str1 == str2)
print("\n--- Hello 每个字符的 ASCII 码 ---")
for char in "Hello":
print(f"字符 {char} 的ASCII码{ord(char)}")
print("\n--- chr() 函数验证 ---")
result = chr(65)
print(f"数字65通过chr()转换后是:{result}")
print(f"65对应字符是否为大写A{result == 'A'}")
#第二题
import math
A = [3, 4]
B = [1, 2]
add_result = [A[0] + B[0], A[1] + B[1]]
print("A + B =", add_result)
mul_result = [2 * A[0], 2 * A[1]]
print("2 × A =", mul_result)
norm_A = math.sqrt(A[0]**2 + A[1]**2)
print("A 的模 =", norm_A)