1.打印操作

>>> print('hello')
hello
>>> print(1+2)
3

2.字符串操作

print(1+2+'')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print(1+2+'')
TypeError: unsupported operand type(s) for +: 'int' and 'str' #整数与字符串不能相加

>>> print('hello'*7)
hellohellohellohellohellohellohello #整数能与字符串相乘
>>> print('hello'*7.0)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
print('hello'*7.0)
TypeError: can't multiply sequence by non-int of type 'float' #浮点数不能与字符串相乘

3.类型转化

①字符串转化为整数

>>> print(int("") + int(""))
5

②输入数据+类型转化+数据相加

>>> float(input("num1:"))+float(input("num2:"))
num1:30
num2:2
32.0

③关于报错

int(input("num1:"))
num1:2.0
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
int(input("num1:"))
ValueError: invalid literal for int() with base 10: '2.0' #输入为浮点数,与int不符

④例子

>>> float(""*int(input("enter a number:")))
enter a number:2
210210.0 #210210转化为浮点型

4.变量

变量赋初值+变量的删除+输入变量值

>>> a=1
>>> print(a)
1
>>> print(a+3)
4
>>> print(a*2)
2
>>> a="hello"
>>> print(a*2)
hellohello
>>> del a
>>> print(a)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
print(a)
NameError: name 'a' is not defined
>>> a = input("number:")
number:2
>>> print(a)
2

  

5.赋值运算符

>>> a=1
>>> a+=2
>>> print(a)
3
>>> str1="abc"
>>> str1+="def"
>>> print(str1)
abcdef

与c语言相似,但无++等运算符

练习戳下

练习题

最新文章

  1. 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
  2. 关于P2P架构的网络游戏
  3. mvc学习
  4. 教程-关于Owner和Parent的区别
  5. Cakephp 创建无模型的Controller
  6. run_command函数分析
  7. Android与路由器连接服务
  8. 【SqlServer】【问题收集】阻止保存要求重新创建表的更改
  9. 【Unity Shaders】Diffuse Shading——向Surface Shader添加properties
  10. Linux initramfs说明
  11. c++学习过程
  12. mycat 从入门到放弃 (转)
  13. Hive默认数据库修改配置
  14. ogg-01027(长事务)
  15. PHP7.27: connect mysql 5.7 using new mysqli_connect
  16. 【Vue】转-Vue.js经典开源项目汇总
  17. HDFS之append数据到已存在文件中
  18. Struts2(二)工作原理
  19. badboy录制网站出现css样式混乱,网页的图标点击没反应
  20. 环境变量篇getenv putenv setenv

热门文章

  1. js中遇到的一些方法和函数
  2. vue踩坑(一):打包上线
  3. effector - 必应词典
  4. TZOJ 4602 高桥和低桥(二分或树状数组+二分)
  5. PCIe 驱动流程(LTSSM)
  6. redis 3.2.1 centos7
  7. 使用U盘安装CentOS7
  8. Error while executing: am start -n
  9. 6L - 大菲波数
  10. tomcat的缺少tcnative-1.dll的解决