python学习作业D1

来源:互联网 发布:网络流行歌曲大全 编辑:程序博客网 时间:2024/06/07 08:35
lesson1
0. Python是什么类型的语言?
Python是脚本语言(scripting language
1. IDLE是什么?
IDLE是开发python程序的基本IDE(集成开发环境)
2. print()的作用是什么?
打印
3. Python中表示乘法的符号是什么?
python中乘号是*
4.为什么>>>print('I love fishc.com ' * 5)可以正常执行,但>>>print('I love fishc.com ' + 5)却报错?
前者表示将字符串打印五遍,后者不同类型
5.如果我需要在一个字符串中嵌入一个双引号,正确的做法是?
加\转义
或‘I l"o"ve you’
6.为什么我们要使用Python3Python2到底有什么问题?看起来很多程序员依然都在使用Python2
他们最终会用python3的
lesson2
0.什么是BIF
BIF即built-in function内置函数
1. 用课堂上小甲鱼教的方法数一数Python3提供了多少个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', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', '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']


>>> c=['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']
>>> len(c)
72
72个
2.Python看来:'FishC''fishc'一样吗?
不一样,大小写敏感
3.在小甲鱼看来,Python中什么是最重要的?你赞同吗?
缩进
4.这节课的例子中出现了“=”“==”,他们表示不同的含义,你在编程的过程中会不小心把“==”误写成“=”吗?有没有好的办法可以解决这个问题呢?
=赋值;==判断
5.你听说过拼接这个词吗?
听说过
lesson3
0.编写程序:hello.py,要求用户输入姓名并打印你好,姓名!

name=input('请输入您的名字:')
print('hello',name)
1.编写程序:calc.py要求用户输入1100之间数字并判断,输入符合要求打印你妹好漂亮,不符合要求则打印你大爷好丑

calc = input('请输入1到100之间的数字:')
num = int(calc)
if 1 <= num <= 100:
    print('妹妹你好漂亮^^')
else:
    print('大爷你好丑TT')

5.如果非要在原始字符串结尾输入反斜杠,可以如何灵活处理?
原因就是反斜杠会和后面的引号发生转意

str=r'C:\program files\love''\\'

lesson4
0.请问以下代码会打印多少次我爱鱼C

while'c':
    print('我爱鱼C!')
无数次(CTRL+C强制结束
1.请问以下代码会打印多少次我爱鱼C
i = 10
while i:
    print('我爱鱼C!')
    i = i - 1
一次10次
2.请写出与10 < cost < 50等价的表达式

(cost > 10) and (cost < 50)
 
3. Python3中,一行可以书写多个语句吗?
可以,用;隔开
4. Python3中,一个语句可以分成多行书写吗?
可以,用\续行 ‘‘‘ ()等都可以 
5.请问Pythonand操作符C语言的&&操作符有何不同?
在c中,0&&3 = 0,1&&3 = 1在python中,,0 and 3 = 0,1 and 3 = 3
6.听说过短路逻辑(short-circuit logic吗?

逻辑操作符有个有趣的特性:在不需要求值的时候不进行操作。这么说可能比较“高深”,举个例子,表达式 x and y,需要 x 和 y 两个变量同时为真(True)的时候,结果才为真。因此,如果当 x 变量得知是假(False)的时候,表达式就会立刻返回 False,而不用去管 y 变量的值。

这种行为被称为短路逻辑(short-circuit logic)或者惰性求值(lazy evaluation),这种行为同样也应用与 or 操作符,这个后边的课程小甲鱼会讲到,不急。

实际上,Python 的做法是如果 x 为假,表达式会返回 x 的值(0),否则它就会返回 y 的值

0 0
原创粉丝点击