问Python中如何设置数据的类型?

答 1 个回答|248 次阅读
Coco老师 - 官方公众号:青少儿编程学习网
擅长:编程教育网站:https://kidscodes.cn/

在 Python 中,数据类型是在为变量赋值时设置的:


Example                                                  Data Type

x = "Hello World"                                            str

x = 20                                                            int

x = 20.5                                                          float

x = 1j                                                        complex

x = ["apple", "banana", "cherry"]                   list

x = ("apple", "banana", "cherry")                 tuple

x = range(6)                                                range

x = {"name" : "John", "age" : 36}                 dict

x = {"apple", "banana", "cherry"}                 set

x = frozenset({"apple", "banana", "cherry"})frozenset

x = True                                                         bool

x = b"Hello"                                                bytes

x = bytearray(5)                                     bytearray

x = memoryview(bytes(5))                  memoryview

推荐课程 »更多

    推荐知识

    Python精选库大全,青少年Python编程学习总结

    Python最适合青少儿进阶学习的编程语言