1. 使用縮進方式做為程式塊開始結束的標示,程式換行在行末尾加 "\"

2. 元祖(Tuple)數據類型,和List的不同是Tuple不能修改,優點是執行速度比List快,因為不能修改也就比較安全,團隊開發某些情況會用到。

3. Dict字典類型,若鍵有重複時,後面的建值會覆蓋掉前面的。

dict = {"banana": 20, "apple": 30, "orange": 40, "banana": 30}
print(dict["banana"]) #30

字典類型的排列順序是隨機的,與設定的順序不一定相同,所以在讀取時就不能使用index。

dict = {"banana":20, "apple": 30}
result = dict.items() # 取得以[鍵:值]為組合的Array
# [("banana":20), ("apple":30)]
result = dict.setdefault("apple", 50) #
result = dict.setdefault("orange", 80) # create new
fruits = ["apple", "mango", "orange"] #list
numbers = (1, 2, 3) #tuple
alphabets = {'a':'apple', 'b':'ball', 'c':'cat'} #dictionary
vowels = {'a', 'e', 'i' , 'o', 'u'} #set

4. python3 內建了SQLite, 非常方便储存數據,不需要再額外設定database環境

5. pyhon class 的 structure function.

class Person:
def __init__(self, name, age):
self.name = name
self.age = age def myfunc(self):
print("Hello my name is " + self.name) p1 = Person("John", 36)
p1.myfunc() # the function called __init__(), which is always executed when the class is being initiated. # Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created # The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class. # It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class

6. string join

sentence = ['this','is','a','sentence']
'-'.join(sentence)
# this-is-a-sentence

7. function as function argument

def Calculate(func, *args):
print(func(*args)) def Add(arg1, arg2):
return arg1 + arg2 def Sub(arg1, arg2):
return arg1 - arg2 Calculate(Add, 1, 3) #
Calculate(Sub, 1, 3) # -1

另外還有一種 keyword argument的用法,Calulate(func, **keywordArgs)

新手學python之新體驗的更多相关文章

  1. 2个版本并存的python使用新的版本安装django的方法

    2个版本并存的python使用新的版本安装django的方法 默认是使用 pip install django 最新版的django会提示  要求python版本3.4以上,系统默认的版本是2.7.5 ...

  2. ​Python 3 新特性:类型注解——类似注释吧,反正解释器又不做校验

    ​Python 3 新特性:类型注解 Crossin ​ 上海交通大学 计算机应用技术硕士 95 人赞同了该文章 前几天有同学问到,这个写法是什么意思: def add(x:int, y:int) - ...

  3. 新手常见Python运行时错误

    经过整理与在实际中遇到的问题,将新手经常遇到的汇总下,以便自己犯傻又这么干了 1)"SyntaxError :invalid syntax",语法错误 A.查看是否在 if , e ...

  4. [新手必备]Python 基础入门必学知识点笔记

    Python 作为近几年越来越流行的语言,吸引了大量的学员开始学习,为了方便新手小白在学习过程中,更加快捷方便的查漏补缺.根据网上各种乱七八糟的资料以及实验楼的 Python 基础内容整理了一份极度适 ...

  5. [转]17个新手常见Python运行时错误

    原址:http://www.oschina.net/question/89964_62779?p=1 当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的 ...

  6. 【新手学Python】一、基础篇

    由于以前处理数据用Matlab和C,最近要处理大量文本文件,用C写实在是太繁琐,鉴于Python的强大文本处理能力,以及其在Deep Learning上有着很大优势,本人打算从即日起学习Python, ...

  7. 【新手】python爬虫遍历贴吧用户

    想法是遍历学校贴吧的用户,获取用户的数据用来分析,因为是初学python,就一点一点的写,变量命名也不规范,见谅 系统:windows 版本:python 3.5 #获取河北大学工商学院吧1000页以 ...

  8. 新手学习Python时常见的错误

    最近学习Python,现在把一些常见的错误总结如下: 1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 "Synta ...

  9. python的Error集,17个新手常见Python运行时错误

    python及相关工具安装Error集 . 如果升级python版本中出现error .so.1.0: cannot open shared object file: No such file or ...

随机推荐

  1. django小知识(2)

    昨日内容回顾 1.choices参数 class Userinfo(models.Model): username = ... age = ... gender_choice = ( (1,'male ...

  2. git 撤销merge

    如果没有别的操作,直接回到上一次提交就可以了,在a分支执行 git reset --hard HEAD~ 会回到未merge前的状态,清空暂存区,销毁数据,如果没有推送到远程,数据就会被覆盖无法恢复, ...

  3. AHOI2014 奇怪的计算器 和 HDU5306 Gorgeous Sequence

    线段树秀操作题. 奇怪的计算器 有 N 个数,一共会对这 N 个数执行 M 个指令(对没个数执行的指令都一样),每一条指令可以是以下四种指令之一:(这里 a 表示一个正整数) 加上 a 减去 a 乘以 ...

  4. CMDS目的端数据库碎片整理记录

    CMDS目的端数据库碎片整理记录 看看数据库里面需要做整理的表有哪些,条件可以根据需求稍微改动一下 SQL> select * from ( 2 select a.owner, 3 a.tabl ...

  5. python + redis +ipset实现IP黑名单的动态添加及解封禁

    1.抽空用python做了一个 动态添加/删除IP黑名单 的程序(或者说实现方案),项目地址: https://gitee.com/lowmanisbusy/ip_blacklists, 2.这里的实 ...

  6. wordpress去掉自定义菜单的外层div

    wordpress调用自定义菜单时自动会在外层加一个<div class="menu-nav-container">,如下图所示,nav是后台定义的菜单名称,如果想把这 ...

  7. Java-Eclipse-findbugs-sonar学习

    一.findbugs 和sonar的安装 可以通过Eclipse的Help-Eclipse marketplace中安装. 推荐:findbugs安装Help-install new Software ...

  8. Python高级函数--map/reduce

    名字开头大写 后面小写:练习: def normalize(name): return name[0].upper() + name[1:].lower() L1 = ['adam', 'LISA', ...

  9. Hibernate学习:Exception in thread "main" java.lang.NullPointerException

    1.在学习Hibernate多对多关系的时候遇到了一下异常: 主函数出现了空指针异常: public static void testadd() { Session session = Hiberna ...

  10. 使用s3-sftp-proxy 暴露minio s3 数据为sftp 访问

    尽管s3 很不错,但是ftp 也有自己存在的价值,以下是一个简单的通过s3-sftp-proxy 暴露minio s3 数据为ftp 的访问方式 环境准备 docker-compose 文件 vers ...