易截截图软件、单文件、免安装、纯绿色、仅160KB

Python 3.x (1):入门

 
1 你好
#打开新窗口,输入:
#! /usr/bin/python
# -*- coding: utf8 -*- 
s1=input("Input your name:")
print("你好,%s" % s1)
'''
知识点:
    * input("某字符串")函数:显示"某字符串",并等待用户输入.
    * print()函数:如何打印.
    * 如何应用中文
    * 如何用多行注释
'''    
2 字符串和数字
但有趣的是,在javascript里我们会理想当然的将字符串和数字连接,因为是动态语言嘛.但在Python里有点诡异,如下:
#! /usr/bin/python
a=2
b="test"
c=a+b
运行这行程序会出错,提示你字符串和数字不能连接,于是只好用内置函数进行转换
#! /usr/bin/python
#运行这行程序会出错,提示你字符串和数字不能连接,于是只好用内置函数进行转换
a=2
b="test"
c=str(a)+b
d="1111"
e=a+int(d)
#How to print multiply values
print ("c is %s,e is %i" % (c,e))
'''
知识点:
    * 用int和str函数将字符串和数字进行转换
    * 打印以#开头,而不是习惯的//
    * 打印多个参数的方式
    '''
3 列表
#! /usr/bin/python
# -*- coding: utf8 -*-
#列表类似Javascript的数组,方便易用
#定义元组
word=['a','b','c','d','e','f','g']
#如何通过索引访问元组里的元素
a=word[2]
print ("a is: "+a)
b=word[1:3]
print ("b is: ")
print (b) # index 1 and 2 elements of word.
c=word[:2]
print ("c is: ")
print (c) # index 0 and 1 elements of word.
d=word[0:]
print ("d is: ")
print (d) # All elements of word.
#元组可以合并
e=word[:2]+word[2:]
print ("e is: ")
print (e) # All elements of word.
f=word[-1]
print ("f is: ")
print (


相关文档:

Python笔记(5)

模块
 
一.简介
模块基本上就是一个包含了所有你定义的函数和变量的文件。为了在其他程序中重用模块,模块的文件名必须以.py为扩展名。
 
例如:
 
#!/usr/bin/python
# Filename: using_sys.py
import sys
print 'The command line arguments are:'
for i in sys.argv:
print i
print '\n ......

python的wiki 列子.

#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response

def index(request, pagename=""):
"""显示正常页面,对页面的文字做特殊的链接处理"""
......

Python内建函数之——filter,map,reduce

     在讲述filter,map和reduce之前,首先介绍一下匿名函数lambda。
     lambda的使用方法如下:lambda [arg1[,arg2,arg3,...,argn]] : expression
     例如:
     >>> add = lambda x,y : x + y
>>> add ......

gentoo卸载Python导致emerge不能使用解决方法

今天一不小心把Python给卸载掉了,导致emerge不能使用,最终找到如下解决方案:
wget http://www.python.org/ftp/python/2.4.4/Python-2.4.4.tar.bz2\
tar xjvf Python-2.4.4.tar.bz
cd Python-2.4.4
./configure –with-fpectl –infodir=/usr/share/info/ –mandir=/usr/share/man
make
make instal ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号