Python-3 语法
#1 Tab键:
1)控制缩进
2)IDLE智能补全
#2 =等号:
1)=:表示赋值
2)==:表示判断
#3 流程图:
print('..........小甲鱼_1..........')
temp=input('猜测小甲鱼心里想的是哪个数字:')
guess=int(temp)
if guess==8:
print('中了')
print('哼,中了也没有奖励')
else:
print('猜错啦,小甲鱼想的是8!')
print('游戏结束,不玩了。')
改进:
1)条件 if-else
2)循环 while and
3)import random 模块:random.randint函数-返回一个随机的整型
import random
secret = random.randint(1,10)
print('..........小甲鱼_1..........')
_continue = input('''是否参与游戏?
是:Y\n''')
if _continue == 'Y':
temp = input('猜测小甲鱼心里想的是哪个数字:')
guess = int(temp)
while guess and _continue == 'Y':
if guess == secret:
print('中了')
print('哼,中了也没有奖励')
break
else:
if guess > secret:
print('大了大了!')
_continue = input('''是否继续猜测?
继续:Y\n''')
temp = input('继续猜测小甲鱼心里想的是哪个数字:')
guess = int(temp)
else:
print('小了小了!')
_continue = input('''是否继续猜测?
继续:Y\n''')
temp = input('继续猜测小甲鱼心里想的是哪个数字:')
guess = int(temp)
else:
print('游戏结束,不玩了。')
#4 内置函数 print、input
>>> 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__', '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(input)
Help on built-in function input in module builtins:
input(...)
input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
Python-3 语法的更多相关文章
- python之最强王者(2)——python基础语法
背景介绍:由于本人一直做java开发,也是从txt开始写hello,world,使用javac命令编译,一直到使用myeclipse,其中的道理和辛酸都懂(请容许我擦干眼角的泪水),所以对于pytho ...
- Python基本语法[二],python入门到精通[四]
在上一篇博客Python基本语法,python入门到精通[二]已经为大家简单介绍了一下python的基本语法,上一篇博客的基本语法只是一个预览版的,目的是让大家对python的基本语法有个大概的了解. ...
- Python基本语法,python入门到精通[二]
在上一篇博客Windows搭建python开发环境,python入门到精通[一]我们已经在自己的windows电脑上搭建好了python的开发环境,这篇博客呢我就开始学习一下Python的基本语法.现 ...
- python 缩进语法,优缺点
Python的语法比较简单——采用缩进方式 缩进有利有弊: 好处之一是强迫你写出格式化的代码,但没有规定缩进是几个空格还是Tab.按照约定俗成的管理,应该始终坚持使用4个空格的缩进. 其二是强迫你写出 ...
- Python特殊语法:filter、map、reduce、lambda [转]
Python特殊语法:filter.map.reduce.lambda [转] python内置了一些非常有趣但非常有用的函数,充分体现了Python的语言魅力! filter(function, s ...
- Python 基础语法(三)
Python 基础语法(三) --------------------------------------------接 Python 基础语法(二)------------------------- ...
- Python基本语法初试
编程环境: win7旗舰版 Python 3.2.2(default, Sep 4 2011,09:51:08) 代码来源:(Python菜鸟) 代码内容: Python基本的输出语句print(& ...
- Python 基础语法(四)
Python 基础语法(四) --------------------------------------------接 Python 基础语法(三)------------------------- ...
- Python 基础语法(二)
Python 基础语法(二) --------------------------------------------接 Python 基础语法(一) ------------------------ ...
- Python 基本语法1
Python 基础语法(一) Python的特点 1. 简单 Python是一种代表简单思想的语言. 2. 易学 Python有极其简单的语法. 3. 免费.开源 Python是FLOSS(自由/开放 ...
随机推荐
- html中的空格显示问题
像这种,从后台查询出来的数据中间有好几个空格,但在页面上显示的时候就只剩一个空格了,这种显示肯定是不合适的,相关的html代码如下: <c:forEach items="${list} ...
- js判断类型方法
在JavaScript中,有5种基本数据类型和1种复杂数据类型,基本数据类型有:Undefined, Null,Boolean, Number和String:复杂数据类型是Object,Object中 ...
- C语言标准库函数(网络上copy的)
C语言标准库函数 标准io函数Standard C I/Oclearerr() clears errorsfclose() close a filefeof() true if at the end- ...
- Exynos 4412
Exynos 4412采用了三星最新的32nm HKMG工艺,是三星的第一款四核处理器 1.启动 有时间再接着写……
- HDU 5964 平行四边形
假设直线L和L'相交于原点O.假设S ={s1,s2,...,sn}是平面上的n个点.你打 算找四个点满足如下条件:1. A ∈ L 而 A' ∈ L'.2. B,B'都属于S;即 B∈S 且 ...
- 微信收藏导出到PC端的方法,不要再傻傻的用网页版转换了!
微信里面收藏了很多有意思的东西,想转到PC上保存起来,以防万一哪天链接失效了. 另外PC上面看,屏幕大一些,也爽一些. 以前的方法是需要通过网页版来传输一下,现在微信有了PC客户端,很方便,直接安装P ...
- 从0和1到Python
什么是编程语言? 举一个例子: 如果我们不会英语,和一个不会中文的老外交流,怎么办?找个翻译. 电脑只懂0和1组成的机器语言. 用0和1告诉计算机做事很累:人类语言易了解,学习快,效率高. 如果定义一 ...
- 一般处理程序上传文件(html表单上传、aspx页面上传)
html 表单上传文件 一般处理程序由于没有 apsx 页面的整个模型和控件的创建周期,而比较有效率.这里写一个用 html 表单进行文件上传的示例. 1. 表单元素选用 ...
- Python isinstance() type()
isinstance(object, classinfo) 判断实例是否是这个类或者object是变量 classinfo 是类型(tuple,dict,int,float,long...)(包括自定 ...
- jersy服务,将图片发送另个服务器,再将异步返回
今天在学习新项目时,遇到了jersy服务,完成,将图片发送到另一台服务器.下面介绍一下jersy服务的一个简单例子. 1.建立一个jersy一个java项目,先导入jersy服务相应的jar包 com ...