len()
type(a)
print ('hello' * 4)
输入input
a = int(input('Enter an integer: '))
元组tuple_小括号(不能重新赋值、删除)
tuple_a = (2,)
number = (1,2,3)
number[1]
temp = ('tom', 18, True)
列表list_中括号:
函数:len(list)、max(list)……
方法:list.reverse()、list.sort([func])……
nubmer = [1,2,3]
del number[1]
print ("number: " + str(number))
cities = ['Nanjing', 'Jian', 'Shenyang']
len(cities)得3
print cities[1]
字典dictionary_大括号(键值对,key和value)
tom = {'name': 'tom', 'age': 18}
print tom['name']
grade = {'tom':99, 'nancy':86, 'landy':90}
print ("nancy: " + str(grade['nancy']))
条件语句
a = 12
if a > 10:
print True
else:
print False
循环语句
str = 'hello'
for i in str:
print i
for i in range(1,10):
print(i)
else:
print('the for loop is over')
list_a = [1,3,5]
for i in list_a:
print(i)
函数
def getName():
return 'tom'
def getName(name):
return 'hello ' + name
def multiParas(a, *b, **c):
print(str(a) + srt(b) + str(c))
调用函数
print getName()
print getName('nancy')
multiParas("hello",1,3,5,word="python",another="c++")
模块
法一:
import math
math.sin(30)
math.cos(30)
法二:
from math import *
sin(30)
cos(30)
range(5)得[0,1,2,3,4]
自定义模块
文件名:test.py
def getName(name):
return 'hello ' + name
调用自定义模块
from test import *
getName('tom')得hello tom
类
文件名: test.py
class People(object):
def getName(self, name)
return 'hi ' + name
使用类
from test import *
student_01 = People() #实例化一个类
student_01.getName('tom')