Python基础(1)

Python基础(1)

基础语法

# 整除运算,向下取整
1 // 2

标识符:数字字母下划线。不能以数字开头

# 获取用户输入,返回字符串
c = int("c:")
print(int(c))
# 幂运算
2 ** 3
pow(2,3)
# 绝对值
abs(-3)
# 取最接近整数,在两个整数一样接近时取偶数
round(2/3)

math

# from math import sqrt
import math
# 向下取整
math.floor(15.8)
# 向上取整
math.ceil(15.2)
# 求平方根
math.sqrt(9)

cmath --- 对复数的支持

字符串

原则上来说''和""的字符串都是一样的,但是实际使用时要配对

"hello"
'hello'
'"hello" he said'
# 转译 \
'It \'s apple.'
# 拼接
let 's say" '"hello world"'
x = "hello"
y = "world"
x+y
# 屏蔽转译
print(repr("hello\nworld"))
print(str("hello\nworld"))

长字符串

# '''
print('''long string 
end here''')
# 常规字符串横跨多行
print("hello \
world")

原始字符串

# 保留原始字符串不转译
print(r'C:\windows')

posted @ 2020-08-09 08:21  Dave-Mo  阅读(29)  评论(0)    收藏  举报