本喵目前跟着莫烦先生学习python
Part1:安装
- Mac
- Windows
- Linux
- 网上有很多教程,我就不复制粘贴了,过程很简单。我用的是pycharm至于激活码都是用晚上的,本喵暂时买不起正版,我的win电脑和mac电脑都装了,都很好用;小例子用idle
Part2:基本使用
print功能
- print 字符串
- print 字符串叠加
- 简单运算
小结
- 1.字符串输出可以用单引号或双引号;可以使用()也可使用空格
- 2.字符串叠加可以直接用+号将两个字符串合并
- 3.相同数据类型(int float char等)可以直接四则运算
- eg:一个字符串不可以于数字进行运算
>>> 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
基础数学运算(四则运算:+-*/)
- 基本的加减乘除
- ”^” 与 “**”
- 取余数 “%”
小结
- 1.可以直接运算数字,也可以使用print进行运算并输出
- 2.次方用^输出无效,用**表示次方
- eg:2的6次方-->2**6
- 3.%表示取余,结果为int
- eg:10%3-->10除以3的余数
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
- 自变量命名规则
小结
- 1.自变量:为程序员取名、使用,也就是标识符,可以用于储存信息
- 2.自变量命名中可以使用下划线_隔开
- 3.可以一次性定义、赋值、输出多个自变量,使用逗号隔开
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
网友评论