day1-python准备工作

2017-08-23  本文已影响13人  喵鸢

本喵目前跟着莫烦先生学习python

Part1:安装

Part2:基本使用

print功能

小结

>>> print(1)
1
>>> print()
()
>>> print('hello world')
hello world
>>> print("hello world")
hello world
>>> print 'hello world'
hello world
>>> print ('hello'+'world')
helloworld
>>> print 1+2
3
>>> print 3-4
-1
>>> print 4*5
20
>>> print 10/5
2
>>> print 12/5
2
>>> print 12.0/5
2.4
>>> print 12/5.0
2.4
>>> print 12/4
3
>>> print 'who'+ 5

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    print 'who'+ 5
TypeError: cannot concatenate 'str' and 'int' objects
>>> print int('2')+ 3
5
>>> print int(1.8)
1
>>> print float(1.5)+3
4.5

基础数学运算(四则运算:+-*/)

小结

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 1+3
4
>>> 4-10
-6
>>> 4*9
36
>>> 10/3
3
>>> 3^2
1
>>> 3**2
9
>>> 2^6
4
>>> 2**6
64
>>> 10%3
1

变量variable

小结

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> apple = 1
>>> print apple
1
>>> phone = 'iPhone 6 plus'
>>> print phone
iPhone 6 plus
>>> phone_2017 = 'iPhone 7'
>>> print phone_2017
iPhone 7
>>> a,b,c=1,2,3
>>> print a,b,c
1 2 3
上一篇 下一篇

猜你喜欢

热点阅读