Python基础复习_Unit one

一. 编译&&安装Python2.7

 

 
1.安装python第三方模块管理工具
easy_install --->> easy_install-2.7 pip

Ipython #Python友好的交互界面

pip2.7 install ipython #通过pip安装Ipython
 
Pycharm 支持IDE图形界面编程

二.我们可以学到什么
python-基础语法
python-面向对象
python-多线程,socket,log,zmq
python-web端-Flask(HTML,CSS,DIV,JS)#前端,后台接口
[saltstack(基于python)-基本使用,二次开发;    zabbix(python-api)-支持二次开发]     ------------------- 基于二次开发

Docker,(Hadoop,spark)大数据---拓展课程



三.第一天学习课程
 
变量;变量的操作;判断;循环


1.变量(Variable Types)

a = 1  #标量,'',"";代表的是字符串(字符串和变量的区别)
 
a = [1,2,3,4] a[0]; #0代表下标,数组的下标

a = {'a'=0;'b'=1,'c'=2};  #a['a'] = 'value1'

2.字符的切片
把一个字符串当作数组来操作;

IndexError:string index out of range   #下标越界

str = 'Hello World!'


print str       #[开始:结束]
print str[0]
print str[2:5]
print str[2:]
print str * 2
print str+"TEST"
print str[-1]
print str[-1:-3]
print str[-5:-1]



3.list操作         #使用中括号包起来
list = ['abcd',786,2.23,'aaa']

4.元组          #使用小括号包起来

5.字典          #使用大括号包起来
tinydict = {'name':'john',code:678,'dept':'sales'}
print dict['one']
print dict[2]
print tinydict

print tinydict.keys()    #输出字典的key值
print tinydict.values() #输出字典的values的值


6.基本的操作(数字操作)

(1)算数运算操作(+,-,*,/)
 
(2)比较操作(>,<,==,!=)

(3)赋值操作(把右边的东西,扔给了左边;+=,-=,*=,/=)
a = a+1 等价于  a+=1

(4)比特运算(把两个变量编程二进制,然后进行"与或非"操作);二进制的比较速度更快

(5)逻辑操作(与或非)

not        #取反

(6)成员操作(是否在范围见 in,not in)

(*7)标识操作(通过Id比较;对于变量的操作)

a=1 
id(a)

b=1
id(b)

a is b 

赋值练习
a = 21
b = 10
c = 0

c = a + b
print "Line 1 - Value of c is ",c 

c = a -  b
print "Line 2 - Value of c is ",c

c = a * b 
print "Line 3 - Value of c is ",c

c = a / b
print "Line 4 - Value of c is  ",c

c = a % b 
print "Line 5 - Value of c is ",c 

__________________

if;else比较操作
a = 21
b = 10
c = 0

if( a==b ):
    print "Line 1 - a is equal to b"
else:
    print "Line 1 - a is not equal to b"

if( a!=b ):
    print "Line 2 - a is not equal to b"
else:
    print "Line 2 - a is equal to b"

if( a < b ):
    print "Line 4 - a is less than b"
else:
    print "Line 4 - a is not less  than b"

if(a>b):
    print "Line 5 - a is greater than b"
else:
    print "Line 5 - a is not greater than b"


__________________________________________-

7.循环(while;for)         
#条件,循环到什么时候停止;你要设置一个便里那个,或者多个变量,使你的程序能够不断接近这个停止的条件;在循环的过程中你要做什么?
while 条件:
    代码块


for i in 范围:
    代码块

a,b = 0,1 
while  b < 100:
    print b
    a,b=b,a+b

a = [1,2,3,4,5,6,7,8,9,10]
for x in a[::2]:         #步长计算
    print x 


i = 1
print "-" * 50
 
while i < 11:
    n = 1
    while n <= 10:
        print "%4d" %(i*n),    #%d占位","不换行
        n += 1
    print ""
    i+=1
 
print "-" * 50


8.continue&&break

a = raw_input("str":)
print a
 
int()      #类型转换,类型可以互相转换


break                  #跳出整个循环体
continue              #直接回到程序的入口


HomeWork:
正三角,倒三角,等边三角,三角套三角
原文地址:https://www.cnblogs.com/milanin9/p/5062985.html