Python Brush knowledge questions

if :
    elif :
else :
print('{0} \n{1} \n{2}' .format((a + b), (a - b), (a * b)))
print(*[num**2 for num in range(n)], sep = '\n')
DEF F ():
     return for condition Condition # directly back judgment condition true or false
print(*range(1, int(input())+1), sep= '')
x, y, z, n = (int(input()) for _ in range(4))
print ([a, b, c] for a in range(0, x+1) for b in range(0, y+1) for c in range(0, z+1) if a + b + c != n])
i = int(input())
lis = list(map(int,raw_input().strip().split()))[:i]
z = max(lis)
while max(lis) == z:
    lis.remove(max(lis))

print max(lis)
n = int(input())
marksheet = [[input(), float(input())] for _ in range(n)]
second_highest = sorted(list(set([marks for name, marks in marksheet])))[1]
print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest]))
if __name__ == '__main__':
    n = int(input())
    student_marks = {}
    for _ in range(n):
        name, *line = input().split()
        scores = list(map(float, line))
        student_marks[name] = scores
    query_name = input()
    query_scores = student_marks[query_name]
    print("{0:.2f}".format(sum(query_scores) / (len(query_scores))))
L = []
for _ in range(0, int(input())):
    user_input = input().split(' ')
    command = user_input.pop(0)
    if len(user_input) > 0:
        if 'insert' == command:
            eval("L.{0}({1}, {2})".format(command, user_input[0], user_input[1]))
        else:
            eval("L.{0}({1})".format(command, user_input[0]))
    elif command == 'print':
        print(L)
    else:
        the eval ( " L. {0} () " .format (Command))
 # the eval () converts the insert, pop, print command character into other str, execution
print raw_input() == 0 or hash(tuple(map(int, raw_input().split(' '))))
DEF swap_case (S):
     return  s.swapcase ()  # letter case change function

if __name__ == '__main__':
    s = input()
    result = swap_case(s)
    print(result)
DEF split_and_join (Line):
     return  " - " .join (line.split ( "  " ))  # first separated using symbols instead of

if __name__ == '__main__':
    line = input()
    result = split_and_join(line)
    print(result)
import sys
import xml.etree.ElementTree as etree

def get_attr_number(node):
    return sum([len(elem.items()) for elem in tree.iter()])

if __name__ == '__main__':
    sys.stdin.readline()
    xml = sys.stdin.read()
    tree = etree.ElementTree(etree.fromstring(xml))
    root = tree.getroot()
    print(get_attr_number(root))
import xml.etree.ElementTree as etree

maxdepth = 0
def depth(elem, level):
    global maxdepth
    level += 1
    if level >= maxdepth:
        maxdepth = level
    for child in elem:
        depth(child, level)

if __name__ == '__main__':
    n = int(input())
    xml = ""
    for i in range(n):
        xml =  xml + input() + "\n"
    tree = etree.ElementTree(etree.fromstring(xml))
    depth(tree.getroot(), -1)
    print(maxdepth)
import re

n, m = map(int, input().split())
a, b = [], ""
for _ in range(n):
    a.append(input())

for z in zip(*a):
    b += "".join(z)

print(re.sub(r"(?<=\w)([^\w]+)(?=\w)", " ", b))
import numpy as np
print(np.array(input().split(),int).reshape(3,3))
n, m = map(int, input().split())
array = numpy.array([input().strip().split() for _ in range(n)], int)
print (array.transpose())
print (array.flatten())
import numpy as np
a, b, c = map(int,input().split())
arrA = np.array([input().split() for _ in range(a)],int)
arrB = np.array([input().split() for _ in range(b)],int)
print(np.concatenate((arrA, arrB), axis = 0))

Guess you like

Origin www.cnblogs.com/HannahGreen/p/12065777.html