Exemplo n.º 1
0
#条件循环&其他语句

from math import sqrt as foobar

print(foobar(4))
#赋值魔法
x, y, z = 1, 2, 3
print(x, y, z)
x, y = y, x
print(x, y, z)
values = 3, 2, 1
print('values: ', values)
x, y, z = values
print('x,y,z:', x, y, z)
scoundrel = {'name': 'robin', 'girlfriend': 'Marion'}
key, value = scoundrel.popitem()
print('key:', key)
print('value:', value)
x = 2
x += 1
x *= 2
print('x:', x)
fnord = 'foo'
fnord += 'bar'
fnord *= 2
print('fnord: ', fnord)
print(bool('42'))
print(bool(''))
print(bool(0))
print(bool(None))
print(bool({}))
Exemplo n.º 2
0
# encoding: utf-8
from math import sqrt as foobar

print foobar(4)
Exemplo n.º 3
0
Arquivo: p04.py Projeto: JyHu/PYStudy
#coding:utf-8


from math import sqrt as foobar	# 使用as将import的函数重命名,避免import的函数有重复的

print foobar(4)

age = 4
assert 0 < age < 100
# assert 10 < age < 100, 'error age'

zname = ['Micky', 'Jane', 'John', 'Ann']
zage = [18, 21, 9, 22]
for name, age in zip(zname, zage):	# zip可以将两个序列合并在一起,合并按少的来
	print name, age

for index, name in enumerate(zname):	# 枚举
	print index, name


f1 = [x * x for x in range(10)]
print f1
f2 = [x * x for x in range(20) if x % 3 == 0]
print f2
f3 = [(x, y) for x in range(3) for y in range(4)]
print f3
f4 = [(x, y) for x in range(5) if x % 2 == 0 for y in range(20) if y % 3 == 0]
print f4
f5 = [x + y + x * y for x in range(10) if x % 2 == 0 for y in range(20) if y % 3 == 0]
print f5
Exemplo n.º 4
0
from math import sqrt as foobar
print(foobar(7))
from math import sqrt as foobar

print(foobar(25))

scoundrel = {'name': 'Robin', 'girlfriend': 'Marion'}
a1, a2 = scoundrel.popitem()
print(a1, a2)

print(bool(0))