Python编程基础与高级概念详解
1. Python数据类型与转换
在Python中,变量的数据类型由其赋值决定。例如:
box_label = "Tools"
car_makers = ['Ford', 'Chevrolet', 'Dodge']
porsche_cars = ('911', 'Cayman', 'Boxster')
address = {"name": "Joe Smith", "Street": "123 Main", "City": "Anytown", "State": "New Happyville"}
这里, box_label 是字符串, car_makers 是列表, porsche_cars 是元组, address 是字典。Python没有像其他语言那样的正式类型规范机制,但可通过初始化来“设置”变量的数据类型。
以下是一些基本数据类型的示例:
float_value = 9.75
integer_value = 5
my_string = "He says, he's already got one."
print("Floating number: {0}".format(float_value))
print("Integer number: {0}".format(integer_value))
print(my_string)
超级会员免费看
订阅专栏 解锁全文
13万+

被折叠的 条评论
为什么被折叠?



