python如何输出值
原创Python中输出值的基本方式是使用print函数,以下是一些例子,展示了如何在Python中输出不同类型的数据。
1、输出字符串:
print("Hello, World!")
2、输出整数:
print(123)
3、输出浮点数:
print(3.14159)
4、输出列表:
print([1, 2, 3, 4, 5])
5、输出字典:
print({"name": "John", "age": 25, "city": "New York"})
6、输出自定义对象的字符串表示:
class Person: def __init__(self, name, age): self.name = name self.age = age def __str__(self): return f"{self.name}, {self.age}" person = Person("John", 25) print(person) # 输出: John, 25
是Python输出值的一些基本示例,在实际编程过程中,可能会输出更复杂的数据结构和自定义对象,但基本方法是一样的。
上一篇:python 如何识别屏幕 下一篇:python如何多行输出