教程:莫烦python
原文地址:https://morvanzhou.github.io/tutorials/python-basic/basic/
win10->打开cmd->输入python
一、print相关
1、print字符串及字符串叠加
>>> print("hello world")
hello world
>>> print("hello world 2")
hello world 2
>>> print('hello world'+'hello china')
hello worldhello china
ps:字符串和数字不能叠加,否则便会报错,如下图:
>>> print('python'+4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str
2、print的简单运算
>>> print(1+1)
2
>>> print(12/4)
3.0
3、print中的int()与float()
ps:当int一个浮点数时,输出会只取其整数部分
>>>