1.range(起始位置)

  range(终止位置)

  range(起始,终止位置)

  range(起始,终止,步长)

2.next(迭代器) 是内置函数

  __next__是迭代器的方法

  g.__next__() 带双下划线的魔术方法一般情况下不直接使用

  next(g)     之前所有的__next__都应该替换成next(g)

3.iter(可迭代的)

  __iter__

  迭代器 = 可迭代.__iter__()

  迭代器 = iter(可迭代的)

4.open("文件名") 跟着操作系统走

  打开模式 默认是r

  编码 默认是 操作系统的默认编码

  

  打开模式 : r w a rb wb ab

  编码 : utf-8 gbk

5.input("字符串数据类型的参数,提醒用户你要输入的内容")

  python2

    input() 还原你输入的值的数据类型

    raw_input = py3.input

  python3

    input() 输入的所有内容都是字符串类型

    阻塞:等待某件事情发生,如果不发生一直等着

  input的返回值就是用户输入的内容

    输入的内容 = input("提示")

6. print(要打印的内容1,要打印的内容2,要打印的内容3,sep = "分隔符",end = "结束符")

  print(123,"abc","阿达",sep = "|")

  f= open("file","w")

  print(123,"abc",file=f)  #print的本质,就是写文件,这个文件是pycharm的屏幕

# import time   # 导入别人写好的代码
# def func():
# for i in range(0,101,2):
# time.sleep(0.1) # 每一次在这个地方阻塞0.1,0.1秒结束就结束阻塞
# char_num = i//2
# if i == 100:
# per_str = '\r%s%% : %s\n' % (i, '*' * char_num)
# else:
# per_str = '\r%s%% : %s' % (i, '*' * char_num)
# print(per_str,end = '')
# func()
# print('下载完成')

7.hash函数

  哈希 可哈希(不可变数据类型) 不可哈希(可变数据类型)

  哈希是一个算法,导致了字典的快速寻址

  "addafaf" 通过hash函数,得到一个数字

  不可变的数据可以通过hash函数的到hash值

8.dir 函数 :特殊的需求,了解一个新的数据类型

print(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']'''

8. eval() 可以将字符串数据类型的python代码执行,通过拼接字符串的方式来执行不同的代码-简化代码

# eval\exec这个函数 不能直接操作文件当中读进来的 网络上传进来 用户输入的
# eval('print(1+2+3+4)') # 有返回值
# ret = eval('1+2/3*4')
# print(ret) # 字符串 -> 其他数据类型的转换
# f = open('userinfo')
# content = f.read()
# print(content,type(content))
# ret = eval(content)
# print(ret,type(ret))
# print(ret[0]) # 员工信息表
# def get_info(f):
# if eval('33 %s 20'%f):
# print('是符合条件的行')
#
# if '>':
# get_info('>')
# if '<' :
# get_info('<') # 9 exec()
# exec('print(1+2+3+4)') # 没有返回值
# ret = exec('1+2/3*4')
# print(ret)
# exec('for i in range(200):print(i)')

10 compile 能够节省时间工具

  先编译 python -编译-> 字节码(bytes) -解释 ->机器码0101010101

# 先整体编译
# code1 = 'for i in range(0,10): print (i)' # 这是一句代码 字符串
#
# compile1 = compile(code1,'','exec') # 预编译 python-> 字节码
# exec (compile1) # 解释
# exec (compile1)
# exec (compile1)
# exec (compile1)
# exec (compile1)
#
# exec(code1) # 编译+解释
# exec(code1)
# exec(code1)
# exec(code1)
# exec(code1) # code3 = 'name = input("please input your name:")'
# compile3 = compile(code3,'','single')
# exec(compile3)
# print(name)
11 help() 函数
# help() 帮助你了解python的
# 方式一
# 输入help() 进入帮助页面,输入数据类型,帮助我们打印具体的帮助信息
# '123'.startswith()
# 输入q退出帮助 # 方式二
# print(help(str))
# print(help('abc'))

12. callable() 判断某一个变量是否可调用

def call(arg):
# if callable(arg):
# arg()
# else:
# print('参数不符合规定')
#
#
# def func():
# print('in func')
# return 1
#
# func2 = 1234
# call(func)
# call(func2)
#
# print(callable(func))
# print(callable(func2))

 

  

day16 Pyhton学习的更多相关文章

  1. Pyhton学习——Day26

    #多态:多态指的是一类事物有多种形态# import abc# class Animal(metaclass = abc.ABCMeta):# 同一类事物:动物# @abc.abstractclass ...

  2. pyhton 学习

    官方学习文档 https://docs.python.org/3/tutorial/

  3. 20190320_head first pyhton学习笔记之构建发布

    1.把代码nester.py放入文件夹nester中,在文件夹中再新建一个setup.py文件,文件内容如下: from distutils.core import setup setup( name ...

  4. Pyhton学习——Day2

    Python开发IDE(工具)Pycharm.eclipse1.循环while 条件 #循环体 #条件为真则执行 #条件为假则执行break用于退出所有循环continue用于退出当前循环 2.Pyc ...

  5. Pyhton学习——Day28

    #上下文协议:文件操作时使用with执行# with open('a.txt','w',encoding='utf-8') as f1:# with语句,为了让一个对象兼容with语句,必须在这个对象 ...

  6. Pyhton学习——Day27

    # hasattr(obj,'name')-->obj.name# getattr(obj,'name',default = 'xxx')--->obj.name# setattr(obj ...

  7. Pyhton学习——Day25

    #面向对象的几个方法#1.静态方法@staticmethod,不能访问类属性,也不能访问实例属性,只是类的工具包#2.类方法:@classmethod,在函数属性前加上类方法,显示为(cls)代表类, ...

  8. Pyhton学习——Day24

    # #面向对象设计:# def dog(name,gender,type):# def jiao(dog):# print('One Dog[%s],wfwfwf'%dog['name'])# def ...

  9. Pyhton学习——Day23

    #re模块方法:findall search#findall:返回所有满足匹配条件的数值,放在列表里#search : #函数会在字符串内查找模式匹配,只到找到第一个匹配然后返回一个包含匹配信息的对象 ...

随机推荐

  1. 2020年1月31日 安装Python的BeautifulSoap库记录

    C:\Users\ufo>pip install beautifulsoup4 Collecting beautifulsoup4 WARNING: Retrying (Retry(total= ...

  2. MyBatis的逆向工程、Example类

    public void testFindUserByName(){ //通过criteria构造查询条件 UserExample userExample = new UserExample(); us ...

  3. redis锁操作

    模拟多线程触发 package com.ws.controller; import io.swagger.annotations.Api; import io.swagger.annotations. ...

  4. Java的ArrayList实现随机生成N-M之间N个不重复的随机数

    在此之前我使用Java的数组实现了产生N-M之间的不重复的随机数,下面是使用数列ArrayList实现同样的功能,代码如下: /** * 随机生成 N--M,N个不重复随机数 使用ArrayList ...

  5. linux基础一(目录结构)

    一.linux目录结构 1.根目录/下 bin:用户二进制文件,常用命令都在此目录下 sbin;这个目录下的linux命令通常由系统管理员使用 etc:包含所有程序所需的配置文件,以及服务的启动文件 ...

  6. 关于如何设置IDEA中的servlet的模板

    关于如何设置IDEA中的servlet的模板 点击左上角的File: Setting --> Editor --> File and Code Templates --> Other ...

  7. FFmpeg开发笔记(四):ffmpeg解码的基本流程详解

    若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...

  8. [LeetCode]69. x 的平方根(数学,二分)

    题目 https://leetcode-cn.com/problems/sqrtx 题解 方法一:牛顿迭代法 按点斜式求出直线方程(即过点Xn,f(Xn)),然后求出直线与x轴交点,即为Xn+1: 求 ...

  9. yum 安装提示公钥安装失败,Public key for .x86_64.rpm is not instal 手动导入公钥方案

    Linux 中yum 安装google-chrome-stable时,报错如下,提示公钥安装失败,原因是 GPG公钥获取失败,无法连接获取到 https://dl-ssl.google.com/lin ...

  10. JVM学习目录

    JVM学习目录 JVM的整体结构 1.类加载子系统 类加载子系统 2.运行时数据区 运行时数据区总览 堆.栈.方法区的详细图解 2.1.程序计数器 程序计数器 2.2.本地方法栈 本地方法栈 2.3. ...