Python入门经典实例.pdf

  1. 1、本文档共12页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
排行榜 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 m ultiply 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 elem ents of word. # 元组可以合并 e= word[:2]+ word[2:] print ( e is: ) print (e) # All elements of word. f= word[-1] print ( f is: ) print (f) # The last elem ents of word. g= word[-4:-2] print ( g is: ) print (g) # index 3 and 4 elements of word. h= word[-2:] print ( h is: ) print (h) # The last two elem ents. i= word[:-2] print ( i is: ) print (i) # Everything except the last two chara

文档评论(0)

lh2468lh + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档