# Python学习之数据类型、函数

Linux编程

https://www.jianshu.com/p/12272a51bfcd

print('''line1

... line2

... line3''')

>>>

line1

line2

line3

Python 3版本中，字符串是以Unicode编码的。

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

List

list是一种有序的集合，可以随时添加和删除其中的元素。

tuple

dict

dict全称dictionary，在其他语言中也称为map，使用键-值（key-value）存储，具有极快的查找速度。

d = {'Michael':95,'Bob':75,'Tracy':85}

d['Michael']

>>>95

set

set和dict类似，也是一组key的集合，但不存储value。由于key不能重复，所以，在set中，没有重复的key。

s = set([1, 1, 2, 2, 3, 3])

s

>>>

Python学习之函数

r1=12.34

r2=9.08

r3=73.1

s1=3.14* r1 * r1

s2=3.14* r2 * r2

s3=3.14* r3 * r3

defmy_abs(x):

ifx >=:

returnx

else:

return-x

importmath

def move(x, y, step, angle=):

nx = x + step *math.cos(angle)

ny = y - step *math.sin(angle)

returnnx, ny

x, y = move(100,100,60,math.pi/6)

defpower(x, n):

s =1

whilen >:

n = n -1

s = s * x

returns

defenroll(name, gender, age=6, city='Beijing'):

print('name:', name)

print('gender:', gender)

print('age:', age)

print('city:', city)

enroll('Bob','M',7)

defcalc(*numbers):

sum =

forninnumbers:

sum = sum + n * n

returnsum

calc(1,2)

nums = [1,2,3]

calc(*nums)

defperson(name, age, **kw):

print('name:', name,'age:', age,'other:', kw)

extra = {'city':'Beijing','job':'Engineer'}

person('Jack',24, **extra)

>>>name:Jackage:24other:{'city':'Beijing','job':'Engineer'}

defperson(name, age, *, city, job):

print(name, age, city, job)

person('Jack',24, city='Beijing', job='Engineer')

>>> Jack24Beijing Engineer

defperson(name, age, *args, city='Beijing', job):

print(name, age, args, city, job)

person('Jack',24, job='Engineer')

>>> Jack24Beijing Engineer

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20181015B1ROJ600?refer=cp_1026
• 腾讯「云+社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 yunjia_community@tencent.com 删除。

2022-01-22

2022-01-22

2022-01-22

2022-01-22

2022-01-22

2022-01-22

2018-11-23

2018-05-30

2022-01-22

2022-01-22

2022-01-22

2022-01-22