python基础知识--1注释

1.注释

1.1单行注释

#print('hello','world')

1.2多行注释

''' 


'''
"""


"""
2.换行


print("hello I love u")
运行结果

hello
I love u

3.单引号,双引号及转义字符

print('hello world')
print("hello world")
print('''I'm pythonic,I said:"Practice makes perfect" ''')
运行结果:

hello world
hello world
I'm pythonic,I said:"Practice makes perfect

用反斜杠()转义特殊字符

 默认是换行
print('\n')
运行结果:

print('\
')
运行结果:

print('\\\\n')
运行结果:\\n


我们并不想让转义字符生效,我们只想显示字符串原来的意思,这就要用r和R来定义原始字符串
print(r'\n')
运行结果:\n

print(R'\n')
运行结果:\n

4.Python常见数学运算与数学函数

print(2+1)
运行结果:3
print(2-1)
运行结果:1
print(2*3)
运行结果:6
print(1/2)
运行结果:0.5
print(2**3)
运行结果:8
#求余
print(20%6)
运行结果:2
#// 取整
print(20//6)
运行结果:3
# 默认四舍五入保留到整数位
print(round(8.9))
运行结果:8
#abs 绝对值取整
print(abs(-1))
运行结果:1

#math 数学函数
#ceil 向上取整
# floor 向下取整
# trunc 截取整数位
# pow 幂运算
import math
print(math.ceil(5.0))
print(math.floor(5.99))
print(math.trunc(5.98))
print(math.pow(5,2))

运行结果:

5

5

5

25

原文地址:https://www.cnblogs.com/tester007/p/13775828.html