python入门简集

python安装                            

一、windows

1.下载软件:https://www.python.org/downloads/

2.点击可执行文件安装

3.环境变量设置

      计算机->属性->高级系统设置->高级->环境变量->第二内容框path追加python安装路径

二、linux

默认已安装,查看版本是否需要升级

python -V

https://www.python.org/ftp/python/

1、安装gcc,用于编译Python源码

yum install gcc

2、下载源码包,https://www.python.org/ftp/python/

3、解压并进入源码文件

4、编译安装

./configure

make all

make install

5、查看版本

/usr/local/bin/python2.7 -V

6、修改默认Python版本

mv /usr/bin/python /usr/bin/python2.6

ln -s /usr/local/bin/python2.7 /usr/bin/python

7、防止yum执行异常,修改yum使用的Python版本

vi /usr/bin/yum

将头部 #!/usr/bin/python 修改为 #!/usr/bin/python2.6

 

pycharm安装及简单设置                    

一、延长过期时间

1.修改主机时间后延

2.不用激活安装

3.主机时间改回原来设置

二、激活

1.注册码

2.license server

http://idea.imsxm.com/

http://elporfirio.com:1017/

三、简单设置

1.新建项目->新建目录->新建文件

2.文件编码           file->default setting->editor->file encodings  -- utf-8

3.程序文件模板     file->default setting->editor->file and code templates

#!/usr/src/python

# -*- coding:utf-8 -*-

4.鼠标滚动设置     file->settings->general->change font size with ctrl+mouse wheel

输入及流程控制                          

 一、输入

1.input

 v_in=input()

print(v_in)

2.不显示输出信息(只有在shell交互式输入输出下才有用)

 import getpass

v_in=getpass.getpass()

print(v_in) 

二、流程控制

1.if 条件:

      ...

   else: 

      ... 

 

3.if 条件:

        ...

   elif 条件:

        ...

    ...

   else:

        ...

 

三、循环

1.while

while true:

      循环体

      continue

      break

2.for

for range:

    循环体

python重要的基本数据类型                         

一、字符串

v_string

方法

1.索引

v_string[i]

2.去除空格

v_string.strip() 

v_string.lstrip() 

v_string.rstrip() 

3.分割

 v_string.split()  #默认空格分割,可以指定分隔符

4.切片

v_string[0:2]  #不包括结束位置

5.in

 用于条件判断是否存在某些字符

6.长度

len(v_string)

7.转换

str(v_num)

8.字符串拼接

new_str=str1+str2

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

9.类型转换

int<->str

10.占位符

 name = '我叫李杰,性别:%s,我今年%s岁,我在说谎!' %('男',19)

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

 

二、列表

v_list=['asda','fer','mysql','php']

方法

1.索引

 v_list[2]

2.切片

v_list[1::3]

3.in

if 'al' in v_list: #列表是否包含al元素
    pass
if 'al' in v_list[0]: # 列表第一个元素是否包含al字符
    pass 

4.长度

 len(v_list)

5.删除

v_list.remove('fer') # 指定元素本身

del v_list[1]  # 指定位置

6.追加

v_list.append('str')

7.插入

v_list.insert(1,'12q')

8.更新

v_list[1]='asd' 

9.for循环遍历item

 

三、字典

v_dict={

     'name':'geek_ace',

     'pwd':'pWd@0!5'

}

方法

1.索引

 v_dist['name']

2.长度

len(v_dict)

3.删除

del v_dict['name'] 

4.更新

v_dict['pwd']=123123 # 修改

v_dict['time']=0     # 增加

5.循环遍历key value key-value

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

6.列表字典相互嵌套

posted @ 2017-05-05 16:35  geek_ace  阅读(203)  评论(0编辑  收藏  举报