2.Python - print、variable、基础数学运算

本文介绍了Python的基本打印功能,包括字符串的使用与连接、基础数学运算、变量定义等内容,并提供了示例代码帮助理解。


  1. python print 字符串 要加''或者""

print('hello world')

print("hello world 2")


  1. 可以使用 + 将两个字符串链接起来, 如以下代码.

print('Hello world'+' Hello Hong Kong')


  1. 可以直接print 加法+,减法-,乘法*,除法/. 注意:字符串不可以直接和数字相加,否则出现错误。

print(3*4)


  1. int() float();当int()一个浮点型数时,int会保留整数部分,比如 int(1.9),会输出1,而不是四舍五入。

print(int(1.9))  #int一个浮点型数时,int会保留整数部分

print(float('1.2')+3) #float()是浮点型,可以把字符串转换成小数


基础数学运算

基本的加减乘除

python可以直接运算数字,也可以加print 进行运算.

python当中^符号,区别于Matlab,在python中,^用两个**表示,如3的平方为3**2 , **3表示立方,**4表示4次方,依次类推

取余符号为“%

取整符号为“//


变量 variable

可以将一个数值,或者字符串串附值给自变量,如apple=1 中,apple为自变量的名称,1为自变量的值。 也可以将字符串赋值给自变量 apple='iphone7 plus'

如果需要用多个单词来表示自变量,需要加下划线,如apple_2016='iphone 7 plus’;或者第二个单词首字母大写(驼峰命名),如appleEgg = 12

一次定义多个自变量 a,b,c=1,2,3

给我代码一的运行结果说明和分析。 C:\Users\蓝喲\PycharmProjects\pythonProject4\venv\Scripts\python.exe C:/Users/蓝喲/PycharmProjects/pythonProject4/main.py 2025-05-28 22:54:04.331335: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-05-28 22:54:05.325903: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. C:\Users\蓝喲\PycharmProjects\pythonProject4\venv\lib\site-packages\keras\src\layers\reshaping\flatten.py:37: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead. super().__init__(**kwargs) IDX格式数据验证: 训练集形状: (60000, 28, 28) (60000,) 测试集形状: (10000, 28, 28) (10000,) 2025-05-28 22:54:08.284734: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Epoch 1/5 1875/1875 ━━━━━━━━━━━━━━━━━━━━ 3s 1ms/step - accuracy: 0.8817 - loss: 0.4224 - val_accuracy: 0.9586 - val_loss: 0.1406 Epoch 2/5 1875/1875 ━━━━━━━━━━━━━━━━━━━━ 2s 1ms/step - accuracy: 0.9653 - loss: 0.1182 - val_accuracy: 0.9693 - val_loss: 0.0975 Epoch 3/5 1875/1875 ━━━━━━━━━━━━━━━━━━━━ 3s 1ms/step - accuracy: 0.9770 - loss: 0.0769 - val_accuracy: 0.9744 - val_loss: 0.0767 Epoch 4/5 1875/1875 ━━━━━━━━━━━━━━━━━━━━ 3s 1ms/step - accuracy: 0.9833 - loss: 0.0569 - val_accuracy: 0.9734 - val_loss: 0.0840 Epoch 5/5 1875/1875 ━━━━━━━━━━━━━━━━━━━━ 2s 1ms/step - accuracy: 0.9857 - loss: 0.0442 - val_accuracy: 0.9706 - val_loss: 0.0930 进程已结束,退出代码0
最新发布
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值