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不一样的更多相关文章

  1. python3.4学习笔记(二十一) python实现指定字符串补全空格、前面填充0的方法

    python3.4学习笔记(二十一) python实现指定字符串补全空格.前面填充0的方法 Python zfill()方法返回指定长度的字符串,原字符串右对齐,前面填充0.zfill()方法语法:s ...

  2. python3.4学习笔记(十五) 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)

    python3.4学习笔记(十五) 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) python print 不换行(在后面加上,end=''),prin ...

  3. python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL

    python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL实战例子:使用pyspider匹配输出带.html结尾的URL:@config(a ...

  4. python3.4学习笔记(四) 3.x和2.x的区别,持续更新

    python3.4学习笔记(四) 3.x和2.x的区别 在2.x中:print html,3.x中必须改成:print(html) import urllib2ImportError: No modu ...

  5. python3.4学习笔记(十七) 网络爬虫使用Beautifulsoup4抓取内容

    python3.4学习笔记(十七) 网络爬虫使用Beautifulsoup4抓取内容 Beautiful Soup 是用Python写的一个HTML/XML的解析器,它可以很好的处理不规范标记并生成剖 ...

  6. python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容

    python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI,采用Python语言编写 ...

  7. python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例

    python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例 新浪爱彩双色球开奖数据URL:http://zst.aicai.com/ssq/openInfo/ 最终输出结果格 ...

  8. python3.4学习笔记(十八) pycharm 安装使用、注册码、显示行号和字体大小等常用设置

    python3.4学习笔记(十八) pycharm 安装使用.注册码.显示行号和字体大小等常用设置Download JetBrains Python IDE :: PyCharmhttp://www. ...

  9. python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码

    python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码 python的json.dumps方法默认会输出成这种格式"\u535a\u ...

随机推荐

  1. MAC - 系统升级导致COCOAPODS失效问题

    使用pod install出现如下错误: macdeMacBook-Pro:QRCodeDemo mac$ pod install -bash: /usr/local/bin/pod: /System ...

  2. mui+vue+photoclip做APP头像裁剪上传

    做APP由于项目需要,需要做用户头像上传的功能,头像上传包括拍照和相册选择图片进行上传,这里使用的技术是mui封装的plus,在进行图片裁剪的时候,使用的是photoclip来进行裁剪,由于个人在使用 ...

  3. OC中分类(Category)和扩展(Extension)

    1.分类的定义 category是Objective-C 2.0之后添加的语言特性,中文也有人称之为分类.类别.Category的主要作用是为已经存在的类添加方法.这个大家可能用过很多,如自己给UIC ...

  4. This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in

    地址:http://stackoverflow.com/questions/18852983/eclipse-reports-rendering-library-more-recent-than-ad ...

  5. 通过 Kubernetes 和容器实现 DevOps

    https://mp.weixin.qq.com/s/1WmwisSGrVyXixgCYzMA1w 直到 Docker 的出现(2008 年),容器才真正具备了较好的可操作性和实用性.容器技术的概念最 ...

  6. 洛谷P2661 信息传递 [NOIP2015] 并查集/乱搞 (待补充!

    感觉我好水啊,,,做个noip往年题目还天天只想做最简单的,,,实在太菜辽 然后最水的题目还不会正解整天想着乱搞,,,  虽然也搞出来辽233333 好滴不扯辽赶紧写完去做紫题QAQ 正解:并查集  ...

  7. kubernetes实战(二十):k8s一键部署高可用Prometheus并实现邮件告警

    1.基本概念 本次部署使用的是CoreOS的prometheus-operator. 本次部署包含监控etcd集群. 本次部署适用于二进制和kubeadm安装方式. 本次部署适用于k8s v1.10版 ...

  8. ifconfig 查看网卡信息

    [root@linux-node- sss]# ifconfig eno16777736: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu inet ...

  9. wordpress如何正确自动获取中文日志摘要

    WordPress 函数 get_the_excerpt() 可以获取日志的摘要,如果没有摘要,它会自动获取内容,并且截取.但是由于无法正确统计中文字符数,我爱水煮鱼撰写了下面这个函数来解决这个问题. ...

  10. crontab定时任务-干货案例

    自定义需求:实现消息队列. 1.创建一张mysql表结构 2.编写php脚本,便于sh文件执行 3.编写sh脚本,便于crontab定时执行 4.crontab -e 注册定时任务,如果此步不清楚请参 ...