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一旦初始化就不能修改
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一旦初始化就不能修改
相关文章推荐
- Python 入门笔记
- Python入门笔记(二)
- Python学习笔记整理(十一)python的while和for循环
- Python学习笔记整理(十五)类的编写细节
- 高手整理入门笔记(启动篇)
- Linux操作系统下C语言编程入门学习笔记(...20090601(第一遍学完待整理)...)
- 我自己整理的一点python的学习笔记。后续继续更新
- Python学习笔记整理(九)Python赋值表达式和打印
- Python学习笔记整理(八)Python语句简介
- Python学习笔记整理(十六)类的设计
- Python扩展和嵌入: Cython三分钟入门(笔记)
- Python 入门笔记
- Python入门笔记
- Python学习笔记整理(十)Python的if测试
- Python学习笔记整理(五)Python中的列表.
- Python入门笔记(一)
- [Python入门及进阶笔记]Python-基础-文件处理小结
- Python学习笔记整理(三)Python中的动态类型简介
- Python学习笔记整理(十三)Python模块
- Python学习笔记整理(十七)异常处理