python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样
python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样,IDLE shell编辑器,快捷键:ALT+p,上一个历史输入内容,ALT+n 下一个历史输入内容。#idle中按F5可以运行代码
BIF --> built in functions 查询python有多少BIF内置函数的方法: dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
查询内置函数的用法:help(函数名)如: help(str)
helloworld.py
temp = input("input number:")
guess = int(temp)
if guess == 8:
print("is 8")
else:
print("is 8")
print("tab is useing")
print("out game") frist = 3
second = 8
third = frist + second
print(third) str1 = "string1"
str2 = " string2"
str3 = str1 + str2
print(str3) ------------------------------
input number:8
is 8
out game
11
string1 string2
结束语句不需要分号,:冒号后回车会自动缩进,tab键是有意义的,不仅仅是代码缩进,缩进里面属于同一个逻辑模块。 在非逻辑层次结构的代码前面不能使用空格,tab键。
变量不需要指定类型,会自动转换。python没有"变量",只有"名字"。变量就是可变的,变量使用之前需要先赋值。 数字相加,字符串拼接,字符串属于文本。
#前后必须使用同样的单引号或双引号,必须是英文半角的字符。 print('5' + "8")
#反斜杠可以作为转义字符串,原始字符串在字符串前面加上r即可,在结尾不能加反斜杠的
#跨越多行的字符串:三重引号字符串(可以是三个单引号或者三个双引号),把内容放中间,可当成多行注释使用
print('c:\\now I\'am')
print(''' line1
line3
''')
print("hello\n" * 3) #会打印3次
#注释使用#号,如果是使说明性注释,可以用__doc__ str.__doc__ #输出str函数的文档描述内容 python 的一个特点是不通过大括号 {} 来划定代码块,而是通过...'__doc__', '__eq__', '__format__', '__ge__', '__getattribute...
============================================
#引入外部模块 import random
#random模块,randint(开始数,结束数) 产生整数随机数
import random
secret = random.randint(1,10)
temp = input("请输入一个数字\n")
guess = int(temp)
count = 0;
while guess != secret: #猜错的时候才进入循环条件
if count == 0 and guess > secret:
print("猜大了")
if count == 0 and guess < secret:
print("猜小了")
temp = input("请重新输入\n") #需要在判断之前让用户输入,否则猜对了就直接退出了
guess = int(temp)
count += 1 #不能使用count++这种方式
if count > 2:
print("猜错4次自动退出了")
break #退出循环
if guess == secret:
print("恭喜,你猜对了")
print("猜对了也就那样")
else:
if guess > secret:
print("猜大了")
else:
print("猜小了")
print("游戏结束")
python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样的更多相关文章
- python3.4学习笔记(二十一) python实现指定字符串补全空格、前面填充0的方法
python3.4学习笔记(二十一) python实现指定字符串补全空格.前面填充0的方法 Python zfill()方法返回指定长度的字符串,原字符串右对齐,前面填充0.zfill()方法语法:s ...
- python3.4学习笔记(十五) 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
python3.4学习笔记(十五) 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) python print 不换行(在后面加上,end=''),prin ...
- python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL
python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL实战例子:使用pyspider匹配输出带.html结尾的URL:@config(a ...
- python3.4学习笔记(四) 3.x和2.x的区别,持续更新
python3.4学习笔记(四) 3.x和2.x的区别 在2.x中:print html,3.x中必须改成:print(html) import urllib2ImportError: No modu ...
- python3.4学习笔记(十七) 网络爬虫使用Beautifulsoup4抓取内容
python3.4学习笔记(十七) 网络爬虫使用Beautifulsoup4抓取内容 Beautiful Soup 是用Python写的一个HTML/XML的解析器,它可以很好的处理不规范标记并生成剖 ...
- python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容
python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI,采用Python语言编写 ...
- python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例
python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例 新浪爱彩双色球开奖数据URL:http://zst.aicai.com/ssq/openInfo/ 最终输出结果格 ...
- python3.4学习笔记(十八) pycharm 安装使用、注册码、显示行号和字体大小等常用设置
python3.4学习笔记(十八) pycharm 安装使用.注册码.显示行号和字体大小等常用设置Download JetBrains Python IDE :: PyCharmhttp://www. ...
- python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码
python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码 python的json.dumps方法默认会输出成这种格式"\u535a\u ...
随机推荐
- FastJson 对enum的 序列化(ordinal)和反序列化
目前版本的fastjon默认对enum对象使用WriteEnumUsingName属性,因此会将enum值序列化为其Name. 使用WriteEnumUsingToString方法可以序列化时将Enu ...
- 专访|HPE测试中心总监徐盛:测试新思维-DevOps,持续测试,更敏捷,更快速
2016年7月22日,「HPE&msup软件技术开放日」将在上海浦东新区,张江高科技园区纳贤路799号科荣大厦小楼2楼举办,msup携手HPE揭秘全球测试中心背后的12条技术实践. 徐盛:HP ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- m4a 转 wav
https://blog.csdn.net/zjm750617105/article/details/80148473 sox 不行, ffmpeg 很麻烦, 考虑用 avconv 很简单: 安装: ...
- 打造自己的 JavaScript 武器库
原文 https://segmentfault.com/a/1190000011966867 github:https://github.com/proYang/outils 前言 作为战斗在业务一线 ...
- sql server 备份恢复效率
sql server 备份恢复效率 如何提高备份的速度呢? 其实这个问题和如何让系统跑的更快是一样的,要想系统跑的更快,无非就是:优化系统,或者就是更好更强大的服务器,特别是更多的cpu.更大的内存. ...
- /etc/ssh/sshd_config
线上配置: Port 49142 # 设置SSH监听端口 RSAAuthentication yes # 开启RSA密钥验证,只针对SSHv1 PubkeyAuthentication yes # 开 ...
- R中apply等函数用法[转载]
转自:https://www.cnblogs.com/nanhao/p/6674063.html 1.apply函数——对矩阵 功能是:Retruns a vector or array or lis ...
- python中关于不执行if __name__ == '__main__':测试模块的解决
1.新建测试脚本文件: 2.编辑测试脚本 import unittest import requests import json import HTMLTestRunner ur1 = 'http:/ ...
- unittest之suite测试集(测试套件)
suite 这个表示测试集,不要放在class内,否则会提示"没有这样的测试方法在类里面 ",我觉得它唯一的好处就是调试的时候可以单独调试某个class而已,我一般不用它,调试时可 ...