和某个大大约好这个寒假里每天都自学一点python
于是就这么开始了。我们使用的编辑器是:IDLE python shell 3.6.4
一、python中的print函数
最基本的Hello world
>>> print("hellow world")
遇到的坑:1.C语言写习惯了经常打成printf(多了一个f),导致运行失败
2.python shell环境下 输入完这行代码后直接敲回车就能看到运行结果,不用编译运行
3.python shell 环境下 例如"hellow world " 也能看到结果,但在pycharm这个编辑器里只写“hellow world”运行会报错
查知乎得到的答案是:python shell下是交互环境,它会默认把每一句的返回值输出到屏幕。
二、单引号、双引号、三引号
>>> print('This is a string using a single quote!')
This is a string using a single quote!
>>> print("This is a string using a single quote!")
This is a string using a single quote!
>>> print('''This is a string using a single quote!''')
This is a string using a single quote!
如上所示,三种引号的输出结果是相同的
但请试想一下如果我们想输出 i don't want to go die 时,那么应该怎么办呢?
方法一:
print( "i don't want to go die")
注:开头和结尾成对出现的双引号,定义了这个字符串,而其中的‘ 则被认为是字符串中的一个字符
方法二:
>>> print('i don\'t want to go to die')
转义字符 反斜杠(\) ,使 (')被认为是一个字符
三引号:
三引号的作用:利用三引号可以实现输出多行文本,示例如下
![](https://i-blog.csdnimg.cn/blog_migrate/6d5d3eb8775c24882442d75fb7d998fc.jpeg)
换行输出也可以用换行符\n实现,示例如下
![](https://i-blog.csdnimg.cn/blog_migrate/c77128e2d60e8a92525ecfff3554e831.jpeg)
参考教材:
《python编程入门经典》清华大学出版社
作者: [美]James W. Payne 译者: 张春晖