首先第一个python脚本,hello world。
python比较简单,
print("hello world!!")
当然也可以写成 print "hello world"或者 print ‘hello world’。这涉及到两个问题 一 print为什么可以加括号,2 单引号和双引号的问题。查了一下,3.0以后必须加括号,因为print变成函数了,也就是 那之前应该是命令咯。然后再说引号,貌似是转义字符的问题,如果字符串需要有""那就在外面用''。相反也一样。类似"hello 'a' world"。
然后再加一句注释吧。单行注释是在开头加#,比如:
#hello world
多行注释是三个引号,单引号和双引号都行
'''sadasd
sadasd
asdasd
'''
"""
sadasdada
asdasdsad
"""
python定义函数是 :
def 函数名(参数)代码块
代码块一定要有缩进,函数包含缩进的代码块,直到缩进结束。但是如果有return 不会执行return之后的代码。
def test(name):
return "name:" + name;print "error"
print test("asdas")
结果是:
name:asdas3.数据类型
整型——int——数字
python有5种数字类型,最常见的就是整型int,int python方法很实用。例如:1234、-1234
布尔型——bool——用符号==表示
布尔型是一种比较特殊的python数字类型,它只有True和False两种值,它主要用来比较和判断,所得结果叫做布尔值。例如:3==3 给出True,3==5给出False
字符串——str——用' '或" "表示
例如:'www.iplaypython.com'或者"hello"
列表——list——用[ ]符号表示
例如:[1,2,3,4]
元组——tuple——用( )符号表示
例如:('d',300)字典——dict——用{ }符号表示
例如:{'name':'coco','country':'china'}
Python初学者指南
本文介绍了Python编程的基础知识,包括helloworld示例、函数定义及使用、常见数据类型如整型、布尔型、字符串、列表、元组和字典等。

被折叠的 条评论
为什么被折叠?



