python入门基础

#注释
len()
type(a)
print

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')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值