数值型变量定义:

# 整数型变量
a = 10
b = -5

# 浮点数型变量
c = 3.14
d = -2.5

字符型变量定义:

# 字符串型变量
e = "Hello World!"
f = 'Python is awesome'

字典型变量定义:

# 字典型变量
g = {"name": "Tom", "age": 18, "gender": "male"}
h = {"fruit": "apple", "color": "red"}

列表型变量定义:

# 列表型变量
i = [1, 2, 3, 4, 5]
j = ["apple", "banana", "orange"]

集合型变量定义:

# 集合型变量
k = {1, 2, 3, 4, 5}
l = {"red", "green", "blue"}

数组型变量定义:

# 数组型变量
import numpy as np

m = np.array([1, 2, 3, 4, 5])
n = np.array([1.5, 2.3, 3.7, -4.2])
``
请同学们用Python定义不同类型的变量数值、字符型、字典型、列表、集合、数组

原文地址: https://www.cveoy.top/t/topic/f4Fj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录