您的位置:首页 > 编程语言 > Python开发

Python入门笔记整理

2017-04-18 13:51 204 查看
参考:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000

1.安装Python

首先,从Python的官方网站python.org下载最新的2.7版本,网速慢的同学请移步国内镜像。

2.安装文本编辑器Sbulime或者pycharm

3.创建一个test.py的文件放到F:盘
test.py内容如下:
print 'hello, world'

运行test.py
F:\>python test.py
hello, world

test.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
a=[1,22,333,4444]
for item in a:
print item;
print a;
print a[2];
print a[-1];
a.append("big happy");
print a;
a.insert(0,"admin");
print a;
a.pop(2);
print a;

print 100+200;

print "hello world", 'jumps over', 'the lazy dog';

#name = raw_input('please enter your name: ');
#print name;
#age = int(raw_input('please enter your age: '));
#print age;

b=100
if b>=30:
print "the value of b is:", b;
elif b>=18:
print b;
else:
print -b;

print "I\'m ok."
print r'I\'m ok.'

print True and False;

num =30
if num>=30:
print 'You are old, but do not give up!'
else:
print 'You are young,try your best to be better!'

print 10/3;
print 10%3;

print ord('A');
print chr(65);

print len('ABC')
print len('\xe4\xb8\xad\xe6\x96\x87')

print 'Hi, %s, you have $%d.' % ('Michael', 1000000)

print range(5);

d = {'Michael': 95, 'Bob': 75, 'Tracy': 85, 'Jack':89};
print d['Michael']
d['Jack'] = 90
print d['Jack']
print 'Thomas' in d
d.get('Thomas', -1)
print d
d.pop('Bob')
print d

s1 = set([1, 1, 2, 2, 3, 3])
print s1;
s1.add(4)
print s1;
s1.add(4)
print s1;
s1.remove(4)
print s1;
s2 = set([2, 3, 4, 5])
print s1 & s2;
print s1 |s2;

看到:使用dict和set
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0013868193482529754158abf734c00bba97c87f89a263b000 注:

1.Python程序是大小写敏感的,如果写错了大小写,程序会报错。 2.常见的占位符有:
%d 整数 %f浮点数 %s字符串%x十六进制整数
3.一种有序列表叫元组:tuple。tuple和list非常类似,但是tuple一旦初始化就不能修改
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: