博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python周报第一周
阅读量:4478 次
发布时间:2019-06-08

本文共 2414 字,大约阅读时间需要 8 分钟。

首次写博客,勿喷!以后无特殊声明都是在python3.5下操作。

1.python2和python3最基础的差异

1.print

python2和python3在新手看来最大的差别无异乎是print了,我分别演示下:

liukai@bogon:~$ python -V

Python 2.7.10
liukai@bogon:~$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a="haha"
>>> print a

haha

>>> print(a)

haha

===========================================

liukai@bogon:~$ python3 -V

Python 3.5.1
liukai@bogon:~$ python3
Python 3.5.1 (default, Jan 8 2016, 23:14:28)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a="haha"
>>> print(a)
haha
>>> print a
File "<stdin>", line 1
print a
^
SyntaxError: Missing parentheses in call to 'print'

总结:python3只支持print(),python2都支持。

2.input

root@lktest:~# python -V

Python 2.7.11
root@lktest:~# python
Python 2.7.11 (default, Jan 20 2016, 11:58:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=raw_input("input your number: ")
input your number: hello
>>> a
'hello'
>>> b=input("input your number: ")
input your number: hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined

================================================

root@lktest:~# python3

Python 3.5.1 (default, Jan 3 2016, 03:35:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a=raw_input("input your number: ")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'raw_input' is not defined
>>> a=input("input your number: ")
input your number: hello
>>> a
'hello'

总结:用户输入函数,python2用raw_input(),python3用input()

2.python基础知识

1.数据类型

1.整型

root@lktest:~# python3

Python 3.5.1 (default, Jan 3 2016, 03:35:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a=100
>>> a=-10
>>> a=0

2.浮点型

>>> b=1.23

>>> b=-1.1
>>> b=12.3e8

3.字符串

>>> c="hello"

>>> c="My God"
>>> c="abc\n123"

4.布尔值

>>> d=True

>>> d=False
>>> 6>5
True
>>> 1>4
False

5.空值

空值用None表示,但是None  !=  0

6.变量

>>> e="hello"

>>> f=10
>>> print(e,f)
hello 10

未完待续...

 

转载于:https://www.cnblogs.com/Caesary/p/5473466.html

你可能感兴趣的文章
002
查看>>
WCF服务“*”有零个应用程序(非基础结构)终结点。这可能是因为未找到应用程序的配置文件,或者在配置文件中未找到与服务名称匹配的服务元素,或者服务元素中未定义终结点。...
查看>>
cocos2d 读书随笔《cocos2d-x游戏开发技术精讲》
查看>>
Asterisk 代码架构概述
查看>>
中兴电信光纤猫F450获取管理员密码方法
查看>>
申请TexturePacker 或 PhysicsEditor free licenses
查看>>
kafka启动报错&问题解决
查看>>
nginx反向代理下没有获取到正确的clientIP问题发散
查看>>
python周报第一周
查看>>
IBM MQ 创建以及常见问题集锦
查看>>
Office文件的奥秘——.NET平台下不借助Office实现Word、Powerpoint等文件的解析(1)
查看>>
SQL Server 服务器磁盘测试之SQLIO篇(一)
查看>>
JQ插件写法 扩展JQ方法
查看>>
[LeetCode&Python] Problem 543. Diameter of Binary Tree
查看>>
226 Invert Binary Tree 翻转二叉树
查看>>
《Pro ASP.NET MVC 3 Framework》学习笔记之十六【示例项目SportsStore】
查看>>
IntelliJ IDEA的安装及永久破解
查看>>
C#多线程编程
查看>>
替换空格
查看>>
IntelliJ IDEA2018.1、2017.3激活
查看>>