python语言基础-入门笔记1
2016-07-30 15:19
393 查看
http://edu.51cto.com/course/course_id-1413.html
模块导入
方法(1)
import m
print m.plus(1, 2)
方法(2)
from m import plus
print plus(1, 2)
导入系统模块
import sys.path
from os import *
import string, re
import time,random
import socket, threading
添加到系统目录
sys.path.append(“./dir/”)
第一次赋值创建变量
python中一切皆对象
dir(var)
查看对象类型:变量名._class_
调用对象方法:变量名.方法()
内建数据类型:
boolean,
integer,
float,
string ,“this is a test”
list, [1, 2, 3]
tuple,(1, 2, 3)
dict, {'aa': 18, 'bb': 16}
set,set([0, 1, 3])
表达式比较
= == > < >= <=
表达式组合
and or not
if 1==1:
print "hello"
else:
print "wrong"
if sex== 'boy':
print 'boy'
elif sex== 'girl':
print 'girl'
else:
print 'weather is good'
python 中不存在switch
python 中没有三目运行( a>b?a:b)
python中的循环
for i in ['bob', 'lucy', 'jim']:
print i
for i in range(10):
if i<8:
continue
print i,
break
else:
print 'no break/exception'
i = 0
while i<10:
print i,
i += 1
obj = range(5)
iterator = iter(obj)
try:
while True:
print iterator.next(),
except StopIteration:
pass
函数的定义和调用
#函数名
def welcome():
print(' hello')
#函数名
def welcome(who, action):
print(who + ' ' + action)
python变长参数
def welcome(*args)
print args
>>>welcome('jim', 'is', 'thinking') 元祖
def welcome(**args)
print args
>>>welcome(who=jim', state='is', action='thinking')
字典
参数默认值
def welcome(who, state='is', action='sleeping'):
print who,state, action
函数的返回值
#函数定义
def 函数名(参数列表):
函数体
return obj
模块导入
方法(1)
import m
print m.plus(1, 2)
方法(2)
from m import plus
print plus(1, 2)
导入系统模块
import sys.path
from os import *
import string, re
import time,random
import socket, threading
添加到系统目录
sys.path.append(“./dir/”)
第一次赋值创建变量
python中一切皆对象
dir(var)
查看对象类型:变量名._class_
调用对象方法:变量名.方法()
内建数据类型:
boolean,
integer,
float,
string ,“this is a test”
list, [1, 2, 3]
tuple,(1, 2, 3)
dict, {'aa': 18, 'bb': 16}
set,set([0, 1, 3])
表达式比较
= == > < >= <=
表达式组合
and or not
if 1==1:
print "hello"
else:
print "wrong"
if sex== 'boy':
print 'boy'
elif sex== 'girl':
print 'girl'
else:
print 'weather is good'
python 中不存在switch
python 中没有三目运行( a>b?a:b)
python中的循环
for i in ['bob', 'lucy', 'jim']:
print i
for i in range(10):
if i<8:
continue
print i,
break
else:
print 'no break/exception'
i = 0
while i<10:
print i,
i += 1
obj = range(5)
iterator = iter(obj)
try:
while True:
print iterator.next(),
except StopIteration:
pass
函数的定义和调用
#函数名
def welcome():
print(' hello')
#函数名
def welcome(who, action):
print(who + ' ' + action)
python变长参数
def welcome(*args)
print args
>>>welcome('jim', 'is', 'thinking') 元祖
def welcome(**args)
print args
>>>welcome(who=jim', state='is', action='thinking')
字典
参数默认值
def welcome(who, state='is', action='sleeping'):
print who,state, action
函数的返回值
#函数定义
def 函数名(参数列表):
函数体
return obj
相关文章推荐
- python语言基础-入门笔记2
- 零基础入门学习Python学习笔记第四讲【列表】
- [Python入门及进阶笔记]Python-基础-字典小结
- Python学习笔记(一):基础语法、变量类型、运算符(快速入门篇)
- [Python入门及进阶笔记]Python-基础-数字处理相关模块
- [Python入门及进阶笔记]Python-基础-集合小结
- Python基础语言学习笔记总结(精华)
- 【零基础入门学习Python笔记003】插曲之变量和字符串|课习题答案
- 【个人笔记】002-PHP基础-01-PHP快速入门-02-PHP语言相关介绍输
- 零基础入门学习Python学习笔记第四讲【短路逻辑】
- 【零基础入门学习Python笔记007】了不起的分支和循环1:打飞机框架
- [Java入门笔记] Java语言基础(二):常量、变量与数据类型
- python自学笔记(一) 基础入门
- Python学习入门笔记-基础知识
- [Python入门及进阶笔记]Python-基础-元组小结
- 【零基础入门学习Python笔记013】元祖:戴上了枷锁的列表
- python基础入门学习笔记(1)
- [Python入门及进阶笔记]Python-基础-字符串小结
- python基础教程之简单入门说明(变量和控制语言使用方法)
- python入门基础笔记