Python - 内置函数 - r

# range()
# repr()
# reversed()
# round()

# range()函数示例 [ )
for num in range(1, 6):
    print(num)  # 打印从1到5的数字

# repr()函数示例
string = "Hello, World!"
representation = repr(string)
print(representation)  # 打印字符串的原始表示,包括引号和转义字符

# reversed()函数示例
my_list = [1, 2, 3, 4, 5]
reversed_list = list(reversed(my_list))
print(reversed_list)  # 打印反转后的列表

# round()函数示例
number = 3.14159
rounded_number = round(number, 2)
print(rounded_number)  # 打印四舍五入后的数字

猜你喜欢

转载自blog.csdn.net/qq_43116031/article/details/131056524
今日推荐