print输出函数
# 创建时间: 2023/1/5
#可以输出数字
print(520)
print(52.1)
#可以输出字符串
print('helloworld')
print("helloworld")
#可以输出运算符
print(3+1)
#将数据输出到文件中 ,注意点 1.所指定的盘符在存在 2.使用file=fp
fp = open('E:/pythonProject/text.txt','a+') #a+如果文件不存在就创建,存在就在文件内容后面继续追加
print('helloworld',file=fp)
fp.close()
#不进行换行输出(输出内容在一行当中)
print('hello','world','Python')
转义字符
" \ + n" 换行
" \ + t" 隔空
" \ + r" 进行覆盖
" \ + b" 退格
" \‘ 大家好 ’\ " 隐含转义字符
#原字符,不希望字符串中的转义字符起作用,就使用原字符,就是在字符串之前加上r,或者R
print(r'hello\nworld') #\n无法起作用
#注意事项,最后一个字符不能是反斜杠
变量的使用
# 创建时间: 2023/1/5
name = '玛丽亚'
print(name)
print('标识',id(name))
print('类型',type(name))
print('值',name)
#输出结果
#玛丽亚
#标识 2272340983504
#类型 <class 'str'>
#值 玛丽亚
浮点数计算
a = 3.1415926
print('a',type(a))
m1 = 1.1
m2 = 2.2
print(m1+m2)
from decimal import Decimal
print(Decimal('1.1')+Decimal('2.2'))
input函数的使用
# 创建时间: 2023/1/5
# 输入函数input
present = input('大圣想要什么礼物呢?\n')
print(present, type(present))
# 从键盘录入两个整数,计算两个整数的和
a = input('请输入一个整数:') # 输入的是str类型
b = input('请输入另一个整数:')
print(a+b)
a = int(input('请输入一个整数:')) # 整型之后进行运算
b = int(b)
print('相加之后的结果:', a+b)
运算符
/:除法运算
//:整除运算
**:幂乘运算
运算符的优先级
# ** -> *,/,//,% -> +,- -> >>,<< -> & -> | -> >,<,>=,<=,==,!= -> and -> or -> =