哪个网站做新加坡劳务比较好的,郑州网站的优化,设计制作小车二教学设计,网站申请空间python3.4学习笔记(一) 基本语法 python3不向下兼容#xff0c;有些语法跟python2.x不一样#xff0c;IDLE shell编辑器#xff0c;快捷键#xff1a;ALTp#xff0c;上一个历史输入内容#xff0c;ALTn 下一个历史输入内容。#idle中按F5可以运行代码
BIF -- built i…python3.4学习笔记(一) 基本语法 python3不向下兼容有些语法跟python2.x不一样IDLE shell编辑器快捷键ALTp上一个历史输入内容ALTn 下一个历史输入内容。#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(游戏结束)