python-01 快速上手:基础知识

#第一章 快速上手:基础知识
# 1.1交互式解释器
# 1.2 算法是什么
# 1.3 数和表达式 + - * /(求商) %(求余)
# 十六进制、 八进制 二进制
# print(0xAF) # 16进制 0x 开头
# print(hex(175)) # 10进制转化为 16 进制
# print(0o10) # 8进制 0o 开头
# print(oct(8)) # 10进制转化为 8 进制
# print(0b111111) # 2进制 0b 开头
# print(bin(63)) # 10进制转化为2进制

# 1.4 变量 #字母、数字和下划线(_)构成, 数字不能开头
# 1.5 语句
# 1.6 获取用户输入
#input('输入一个数字:')
# 1.7 函数
# 1.8 模块
# import math
# print(math.floor(32.5))
# # 1.8.1 cmath 和复数
# import cmath
# print(cmath.sqrt(-1))
# 1.8.1 回到未来 __future__
# 1.9 保存并执行程序
#1.9.1 从命令提示符运行Python 脚本
#1.9.2 拼接字符串
#1.9.3 注释 # """"""(三对单引号、双引号)
#1.10 字符串
#1.10.1 单引号字符串以及对引号转义
#1.10.2 拼接字符串
#1.10.3 字符串 str 和 repr
#1.10.4 长字符串、原始字符串和字节
# 长字符串
print('''This is a very long string. It continues here.
And it's not over yet."Hello, world!"
Still here''')

#原始字符串
print("Hello, \n world!") # \n 表示换行
print(r"Hello, \n world!") # 原始字符串用前缀r 表示
#print(r"Hello, \n world!\") # 原始字符串不能以\反斜杠结尾
print(r"Hello, \n world!\\") # 可以对反斜杠转移

#字节
print('\u00C6')
print('this is a cat: \N{cat}')
print('this is a dog: \N{dog}')
print('this is a dog: \N{fish}')
print('this is a dog: \N{dragon}')
print('this is a dog: \N{boy}')


''''
abs(number) 返回指定数的绝对值
bytes(string, encoding[, errors]) 对指定的字符串进行编码,并以指定的方式处理错误
cmath.sqrt(number) 返回平方根;可用于负数
float(object) 将字符串或数字转换为浮点数
help([object]) 提供交互式帮助
input(prompt) 以字符串的方式获取用户输入
int(object) 将字符串或数转换为整数
math.ceil(number) 以浮点数的方式返回向上圆整的结果
math.floor(number) 以浮点数的方式返回向下圆整的结果
math.sqrt(number) 返回平方根;不能用于负数
pow(x, y[, z]) 返回x的y次方对z求模的结果
print(object, ...) 将提供的实参打印出来,并用空格分隔
repr(object) 返回指定值的字符串表示
round(number[, ndigits]) 四舍五入为指定的精度,正好为5时舍入到偶数
str(object) 将指定的值转换为字符串。用于转换bytes时,可指定编码和错误处理方式
'''

猜你喜欢

转载自www.cnblogs.com/fuyouqiang/p/11844609.html