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 ...
随机推荐
- thinkphp----替换写标签的方法
在用thinkphp写cmf的时候,考虑到一些方法的复用,所以考虑使用写标签. 写标签的好处在于:通用,而且比较容易看,但是封装一个标签,个人觉得还是比较麻烦,想了想 thinkcmf 调用文章的方式 ...
- 利用 :first-child 和 :nth-last-child 确定子元素数目
读<css揭秘>时,发现选择器的神奇作用,可以确定子元素数目,比如: li:first-child:nth-last-child(2),li:first-child:nth-last-ch ...
- php小记
php获取日期: date_default_timezone_set('PRC'); //默认时区 "今天:",date("Y-m-d",time()),&qu ...
- 洛谷P2414 阿狸的打字机【AC自动机】【fail树】【dfs序】【树状数组】
居然真的遇上了这种蔡队题.瑟瑟发抖. 题目背景 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机. 题目描述 打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母.经阿 ...
- POJ - 1101 The Game dfs
题意:给你一个地图,上面有一些‘X',给你起点终点,让你输出从起点到终点的路径中转向(改变方向)次数最少的路径,注意,不能穿过别的’X'并且可以超过边界 题解:关于超过边界,只要在外围多加一圈‘ ’. ...
- linux:正则表达式grep命令
基本语法一个正则表达式通常被称为一个模式(pattern),为用来描述或者匹配一系列符合某个句法规则的字符串. 一.选择:| | 竖直分隔符表示选择,例如"boy|girl"可 ...
- firmware 固件
COMPPUTER SCIENCE AN OVERVIEW 11th Edition firmware 固件 boot loader 引导程序 device driver 设备驱动程序 Basic I ...
- Pragma: no-cache
PHP Advanced and Object-Oriented Programming Larry Ullman Last-Modified 最后修改时间 Expires 过期时间 Pragma ...
- iOS多线程编程之线程间的通信(转载)
一.简单说明 线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信 线程间通信的体现 1个线程传递数据给另1个线程 在1个线程中执行完特定任务后,转到另1个线程继续执行任务 ...
- flask中cookie,session的存储,调用,删除 方法(代码demo)
# -*- encoding: utf-8 -*- # cookie,session的存储,调用,删除 from flask import Flask,make_response,request,se ...