1 / 17
文档名称:

Python入门教程-超详细1小时学会Python.docx

格式:docx   大小:1,836KB   页数:17页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

Python入门教程-超详细1小时学会Python.docx

上传人:才艺人生 2022/7/19 文件大小:1.79 MB

下载得到文件列表

Python入门教程-超详细1小时学会Python.docx

文档介绍

文档介绍:Python入门教程-超详细1小时学会Python
Python入门教程 超详细1小时学会Python
为什么使用Python
    假设我们有这么一项任务: key to close this window");
    将该字符集改为我们更熟悉的形式:
# -*- coding: GBK -*-
print "欢迎来到奥运中国!" # 使用中文的例子
raw_input("Press enter key to close this window");
    程序一样运行良好.
方便易用的计算器
    ,直接进行计算:
a=
b=
c=2343
print (a+b+c)/c
字符串,ASCII和UNICODE
    可以如下打印出预定义输出格式的字符串:
print """
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to
"""
    字符串是怎么访问的?请看这个例子:
word="abcdefg"
a=word[2]
print "a is: "+a
b=word[1:3]
print "b is: "+b # index 1 and 2 elements of word.
c=word[:2]
print "c is: "+c # index 0 and 1 elements of word.
d=word[0:]
print "d is: "+d # All elements of word.
e=word[:2]+word[2:]
print "e is: "+e # All elements of word.
f=word[-1]
print "f is: "+f # The last elements of word.
g=word[-4:-2]
print "g is: "+g # index 3 and 4 elements of word.
h=word[-2:]
print "h is: "+h # The last two elements.
i=word[:-2]
print "i is: "+i # Everything except the last two characters
l=len(word)
print "Length of word is: "+ str(l)
    请注意ASCII和UNICODE字符串的区别:
print "Input your Chinese name:"
s=raw_input("Press enter to be continued");
print "Your name is  : " +s;
l=len(s)
print "Length of your Chinese name in asc codes is:"+str(l);
a=unicode(s,"GBK")
l=len(a)
print "I'm sorry we should use unicode char!Characters number of your Chinese \
name in unicode is:"+str(l);
使用List
    类似Java里的List,这是一种方便易用的数据类型:
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: 

最近更新